Esempio n. 1
0
  protected boolean copyAgentAppWarFile(IStateAccess stateAccess) {
    boolean status = false;
    String srcDir = ConfigUtil.getEtcDirPath();
    String destDir = (String) stateAccess.get(STR_KEY_JETTY_INST_DEPLOY_DIR);

    try {
      FileUtils.copyJarFile(srcDir, destDir, STR_AGENT_APP_WAR_FILE);
      Debug.log(
          "ConfigureAgentAppTask.copyAgentAppWarFile() - copy "
              + STR_AGENT_APP_WAR_FILE
              + " from "
              + srcDir
              + " to "
              + destDir);
      status = true;
    } catch (Exception e) {
      Debug.log(
          "ConfigureAgentAppTask."
              + "copyAgentAppWarFile() - Error occured while copying "
              + STR_AGENT_APP_WAR_FILE
              + " from "
              + srcDir
              + " to "
              + destDir,
          e);
    }
    return status;
  }
  /**
   * Returns the product home directory if the locator file is present or returns null. If null =>
   * first time install
   *
   * @return the product home directory
   * @throws InstallException
   */
  protected String getProductHome(IStateAccess stateAccess) throws InstallException {
    String serverHomeDir = getServerHomeDir(stateAccess);
    setProductLocatorFile(serverHomeDir + FILE_SEP + STR_LOCATOR_FILE_NAME);

    String productHome = null;
    File file = new File(getProductLocatorFile());
    if (file.exists() && file.canRead()) {
      // Found old install
      productHome = readProductHome();
      validateProductHome(productHome, getProductLocatorFile());

      if (!productHome.equals(ConfigUtil.getHomePath())) {
        Debug.log(
            "MigrateServerLocatorHandler.validateProductHome() : "
                + "old Product home: "
                + productHome
                + ", New Product Home: "
                + ConfigUtil.getHomePath());

      } else {
        Debug.log("MigrateServerLocatorHandler - Error:" + "This agent has been already migrated!");

        throw new InstallException(LocalizedMessage.get(LOC_DR_ERR_PRODUCT_ALREADY_MIGRATED));
      }
    }

    return productHome;
  }
 public void save() throws InstallException {
   Debug.log("OrderedPropertyStore: Saving the properties to file '" + getFile() + "'.");
   Debug.log("OrderedPropertyStore.load() Saving Contents: " + LINE_SEP + toString());
   BufferedWriter bw = null;
   try {
     if (!getProperties().isEmpty()) { // Data to save is present
       FileWriter fw = new FileWriter(getFile());
       bw = new BufferedWriter(fw);
       int count = getProperties().size();
       // Write the header
       bw.write(getFileHeader() + LINE_SEP);
       for (int i = 0; i < count; i++) {
         bw.write(getProperties().getKeyValueString(i) + LINE_SEP);
       }
     } else { // Nothing to save
       Debug.log("OrderedPropertyStore: No data present in " + "KeyValueMap. Nothing to Save!!");
     }
   } catch (Exception e) {
     Debug.log(
         "OrderedPropertyStore: Error saving the properties " + "to file '" + getFile() + "'.", e);
     throw new InstallException(getSaveErrorMessage(), e);
   } finally {
     if (bw != null) {
       try {
         bw.flush();
         bw.close();
       } catch (IOException i) {
       }
     }
   }
 }
Esempio n. 4
0
 protected boolean removeAgentAppWar(IStateAccess stateAccess) {
   boolean status = false;
   String destDir = (String) stateAccess.get(STR_KEY_JETTY_INST_DEPLOY_DIR);
   String agentAppWar = destDir + STR_FORWARD_SLASH + STR_AGENT_APP_WAR_FILE;
   try {
     File file = new File(agentAppWar);
     status = file.delete();
     Debug.log("ConfigureAgentAppTask.removeAgentAppWar(): " + " Removed file " + agentAppWar);
   } catch (Exception e) {
     Debug.log(
         "ConfigureAgentAppTask.removeAgentAppWar(): " + " Failed to remove file " + agentAppWar,
         e);
   }
   return status;
 }
Esempio n. 5
0
  public boolean rollBack(String name, IStateAccess stateAccess, Map properties)
      throws InstallException {
    boolean status = false;
    boolean skipTask = skipTask(stateAccess);

    if (skipTask) {
      Debug.log("Skipping ConfigureDomainXMLTask.rollback()");
      status = true;
    } else {
      String serverXMLFile = getDomainXMLFile(stateAccess);
      String serverInstanceName = getServerInstanceName(stateAccess);
      if (serverInstanceName == null) {
        // use the default one
        serverInstanceName = DEFAULT_INSTANCE_NAME;
      }
      if (serverXMLFile != null) {
        try {
          File serverXML = new File(serverXMLFile);
          XMLDocument domainXMLDoc = new XMLDocument(serverXML);
          XMLElement instanceConfig = getInstanceConfig(domainXMLDoc, serverInstanceName);
          if (instanceConfig != null) {
            status &= removeAgentRealm(domainXMLDoc, instanceConfig, stateAccess);
            status &= removeLifecycleModule(domainXMLDoc, serverInstanceName, stateAccess);
            if (!VersionChecker.isGlassFishv3(stateAccess)) {
              status = removeAgentClasspath(instanceConfig, stateAccess);
            }
            domainXMLDoc.setIndentDepth(8);
            domainXMLDoc.store();
          }
        } catch (Exception e) {
          status = false;
          Debug.log(
              "ConfigureDomainXMLTask.execute() Error occurred "
                  + "while updating serverXML file '"
                  + serverXMLFile
                  + "'.",
              e);
        }
      } else {
        Debug.log(
            "ConfigureDomainXMLTask.rollBack() Error could get "
                + "server.xml file: "
                + serverXMLFile);
      }
    }

    return status;
  }
Esempio n. 6
0
  private boolean skipTask(IStateAccess stateAccess) {
    boolean result = false;
    String isRemote = (String) stateAccess.get(STR_DAS_HOST_IS_REMOTE_KEY);

    if (isRemote != null) {
      result = Boolean.valueOf(isRemote).booleanValue();
      Debug.log("ConfigureDomainXMLTask: skipTask = " + isRemote);
    }

    return result;
  }
  /*
   * get previous agent's lib path for unconfiguring.
   */
  protected String getLibPath(IStateAccess stateAccess) {
    String libPath = MigrateFromInstFinderStore.getProductHome() + FILE_SEP + INSTANCE_LIB_DIR_NAME;

    String remoteHomeDir = getRemoteHomeDir(stateAccess);
    if (remoteHomeDir != null) {
      libPath = remoteHomeDir + FILE_SEP + INSTANCE_LIB_DIR_NAME;
    }
    Debug.log("MigrateUnconfigureServerPolicyTask.getLibPath() - " + "lib Dir:" + libPath);

    return libPath;
  }
  public void load() throws InstallException {

    BufferedReader br = null;

    Debug.log("OrderedPropertyStore: Loading the properties from file '" + getFile() + "'.");
    try {
      FileReader fr = new FileReader(getFile());
      br = new BufferedReader(fr);
      String lineData = null;
      int lineNumber = 1;
      while ((lineData = br.readLine()) != null) {
        // Ignore Empty lines or commented lines starting with '#'
        if (lineData.trim().length() > 0 && !lineData.startsWith(STR_KEY_COMMENT_MARKER)) {
          int separatorIndex = lineData.indexOf(STR_KEY_VALUE_SEP);
          if (separatorIndex != -1) {
            String key = lineData.substring(0, separatorIndex);
            verifyKeyString(key.trim(), lineNumber);

            // Store the value even if it is empty String
            String value = lineData.substring(separatorIndex + 1);
            getProperties().put(key, value.trim());
          } else { // NO Delimiter '=' found. So throw an exception
            throw new InstallException(getInvalidLineErrorMessage(lineNumber));
          }
        }
        ++lineNumber;
      }
    } catch (Exception e) {
      Debug.log("OrderedPropertyStore: Error loading the properties", e);
      throw new InstallException(getLoadErrorMessage(), e);
    } finally {
      if (br != null) {
        try {
          br.close();
        } catch (IOException i) {
        }
      }
    }
    Debug.log("OrderedPropertyStore.load() Contents: " + LINE_SEP + toString());
  }
 private void validateProductHome(String productHome, String locatorFile) throws InstallException {
   if (productHome == null || productHome.trim().length() == 0) {
     Debug.log(
         "MigrateServerLocatorHandler : Error invalid product home"
             + " property '"
             + IAdminTool.PROP_PRODUCT_HOME
             + " = "
             + productHome
             + "' in file "
             + locatorFile);
     throw new InstallException(LocalizedMessage.get(LOC_DR_ERR_APP_SERVER_HOME_LOCATOR));
   }
 }
  /**
   * Backup the old product home directory before migration.
   *
   * @throws InstallException
   */
  protected void backupProductHome() throws InstallException {

    String locatorFile = getProductLocatorFile();
    try {
      FileUtils.backupFile(locatorFile, STR_BACK_UP_FILE_SUFFIX);
      saveProductHome();

    } catch (Exception e) {
      Debug.log(
          "MigrateServerLocatorHandler - Error occurred "
              + "while backup and deletion for file: '"
              + locatorFile
              + "'.");
      Object[] args = {locatorFile};
      throw new InstallException(LocalizedMessage.get(LOC_DR_ERR_PRODUCT_LOCATOR_BACKUP, args));
    }
  }