CreateLayoutTask.java revision fb379c70e3fd8a537f311b99be4759ae41e02750
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/**
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * The contents of this file are subject to the terms
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * of the Common Development and Distribution License
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * (the License). You may not use this file except in
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * compliance with the License.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * You can obtain a copy of the License at
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * https://opensso.dev.java.net/public/CDDLv1.0.html or
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * opensso/legal/CDDLv1.0.txt
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * See the License for the specific language governing
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * permission and limitations under the License.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * When distributing Covered Code, include this CDDL
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Header Notice in each file and include the License file
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * at opensso/legal/CDDLv1.0.txt.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * If applicable, add the following below the CDDL Header,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * with the fields enclosed by brackets [] replaced by
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * your own identifying information:
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * "Portions Copyrighted [year] [name of copyright owner]"
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * $Id: CreateLayoutTask.java,v 1.3 2008/06/25 05:51:18 qcheng Exp $
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlowpackage com.sun.identity.install.tools.configurator;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlowimport java.io.File;
4bff34e37def8a90f9194d81bc345c52ba20086athurlowimport java.util.Map;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
9c9af2590af49bb395bc8d2eace0f2d4ea16d165Gordon Rossimport com.sun.identity.install.tools.util.ConfigUtil;
9c9af2590af49bb395bc8d2eace0f2d4ea16d165Gordon Rossimport com.sun.identity.install.tools.util.Debug;
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wrightimport com.sun.identity.install.tools.util.FileUtils;
9c9af2590af49bb395bc8d2eace0f2d4ea16d165Gordon Rossimport com.sun.identity.install.tools.util.LocalizedMessage;
9c9af2590af49bb395bc8d2eace0f2d4ea16d165Gordon Rossimport com.sun.identity.install.tools.admin.ToolsConfiguration;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlowpublic class CreateLayoutTask implements ITask, InstallConstants {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow public boolean execute(String name, IStateAccess stateAccess,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow Map properties) throws InstallException {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow String productHome = ConfigUtil.getHomePath();
4bff34e37def8a90f9194d81bc345c52ba20086athurlow String instanceName = stateAccess.getInstanceName();
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow Debug.log("LayoutHandlerTask.execute() - Creating instance "
4bff34e37def8a90f9194d81bc345c52ba20086athurlow + "directory layout for '" + instanceName);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow // Populate the directory paths
4bff34e37def8a90f9194d81bc345c52ba20086athurlow String instanceDirPath = productHome + FILE_SEP + instanceName;
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross String logsDirPath = instanceDirPath + FILE_SEP
4bff34e37def8a90f9194d81bc345c52ba20086athurlow + INSTANCE_LOGS_DIR_NAME;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow String baseConfigDirPath = productHome + FILE_SEP +
4bff34e37def8a90f9194d81bc345c52ba20086athurlow INSTANCE_CONFIG_DIR_NAME;
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross String configDirPath = instanceDirPath + FILE_SEP
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross + INSTANCE_CONFIG_DIR_NAME;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow String debugLogsDirPath = logsDirPath + FILE_SEP
4bff34e37def8a90f9194d81bc345c52ba20086athurlow + INSTANCE_DEBUG_DIR_NAME;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow String auditLogsDirPath = logsDirPath + FILE_SEP
4bff34e37def8a90f9194d81bc345c52ba20086athurlow + INSTANCE_AUDIT_DIR_NAME;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow createDir(instanceDirPath);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow createDir(configDirPath);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow createDir(logsDirPath);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow createDir(debugLogsDirPath);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow createDir(auditLogsDirPath);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow // Add related tokens - which are related to this Layout class
4bff34e37def8a90f9194d81bc345c52ba20086athurlow stateAccess.put(STR_AUDIT_DIR_PREFIX_TAG, auditLogsDirPath);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow stateAccess.put(STR_CONFIG_DIR_PREFIX_TAG, configDirPath);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow stateAccess.put(STR_DEBUG_DIR_PREFIX_TAG, debugLogsDirPath);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow stateAccess.put(STR_DEBUG_LEVEL_TAG, STR_DEBUG_LEVEL_DEFAULT_VALUE);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow stateAccess.put(STR_LOG_CONFIG_FILE_PATH, baseConfigDirPath + FILE_SEP +
4bff34e37def8a90f9194d81bc345c52ba20086athurlow STR_LOG_CONFIG_FILENAME);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow // All the operations should succeed. If one of them does not then an
4bff34e37def8a90f9194d81bc345c52ba20086athurlow // Exception is thrown as it would be a Fatal Exception. Hence this
4bff34e37def8a90f9194d81bc345c52ba20086athurlow // the method always returns a true.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return true;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow public boolean rollBack(String name, IStateAccess stateAccess,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow Map properties) throws InstallException {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow String productHome = ConfigUtil.getHomePath();
4bff34e37def8a90f9194d81bc345c52ba20086athurlow String instanceName = stateAccess.getInstanceName();
9c9af2590af49bb395bc8d2eace0f2d4ea16d165Gordon Ross
9c9af2590af49bb395bc8d2eace0f2d4ea16d165Gordon Ross Debug.log("LayoutHandlerTask.rollBack() - Deleting instance "
4bff34e37def8a90f9194d81bc345c52ba20086athurlow + "directory '" + instanceName + "' and its contents");
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow // Populate the directory paths
4bff34e37def8a90f9194d81bc345c52ba20086athurlow String instanceDirPath = productHome + FILE_SEP + instanceName;
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross File instanceDir = new File(instanceDirPath);
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross return FileUtils.removeDir(instanceDir);
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow public LocalizedMessage getExecutionMessage(IStateAccess stateAccess,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow Map properties) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow Object[] args = { ToolsConfiguration.getProductShortName(),
4bff34e37def8a90f9194d81bc345c52ba20086athurlow stateAccess.getInstanceName() };
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow LocalizedMessage message = LocalizedMessage.get(
4bff34e37def8a90f9194d81bc345c52ba20086athurlow LOC_TSK_MSG_CREATE_LAYOUT_EXECUTE, args);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return message;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow public LocalizedMessage getRollBackMessage(IStateAccess stateAccess,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow Map properties) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow Object[] args = { stateAccess.getInstanceName() };
4bff34e37def8a90f9194d81bc345c52ba20086athurlow LocalizedMessage message = LocalizedMessage.get(
4bff34e37def8a90f9194d81bc345c52ba20086athurlow LOC_TSK_MSG_DELETE_LAYOUT_ROLL_BACK, args);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return message;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow private void createDir(String dirName) throws InstallException {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow Debug.log("LayoutHandlerTask.createDir() - Creating Dir for: "
4bff34e37def8a90f9194d81bc345c52ba20086athurlow + dirName);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow File dir = new File(dirName);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (!dir.mkdir()) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow Debug.log("LayoutHandlerTask.createDir() - Error Unable to "
4bff34e37def8a90f9194d81bc345c52ba20086athurlow + "create Dir for: " + dirName);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow // If the creation is not successful throw an Exception
4bff34e37def8a90f9194d81bc345c52ba20086athurlow LocalizedMessage lMessage = LocalizedMessage.get(
4bff34e37def8a90f9194d81bc345c52ba20086athurlow LOC_DR_ERR_DIR_CREATE, new Object[] { dirName });
4bff34e37def8a90f9194d81bc345c52ba20086athurlow throw new InstallException(lMessage);
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /** Field LOC_DR_ERR_DIR_CREATE **/
4bff34e37def8a90f9194d81bc345c52ba20086athurlow public static final String LOC_DR_ERR_DIR_CREATE = "DR_ERR_DIR_CREATE";
9c9af2590af49bb395bc8d2eace0f2d4ea16d165Gordon Ross
9c9af2590af49bb395bc8d2eace0f2d4ea16d165Gordon Ross public static final String LOC_TSK_MSG_CREATE_LAYOUT_EXECUTE =
9c9af2590af49bb395bc8d2eace0f2d4ea16d165Gordon Ross "TSK_MSG_CREATE_LAYOUT_EXECUTE";
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow public static final String LOC_TSK_MSG_DELETE_LAYOUT_ROLL_BACK =
4bff34e37def8a90f9194d81bc345c52ba20086athurlow "TSK_MSG_CREATE_LAYOUT_ROLLBACK";
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow public static final String STR_DEBUG_LEVEL_TAG = "DEBUG_LEVEL";
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow public static final String STR_DEBUG_LEVEL_DEFAULT_VALUE = "error";
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow