Esempio n. 1
0
  /**
   * Creates the necessary transfer objects to report a failed application deployment (update).
   *
   * @param errorMessage reason the deploy failed
   * @param packageDetails describes the update being made
   * @return response populated to reflect a failure
   */
  private DeployPackagesResponse failApplicationDeployment(
      String errorMessage, ResourcePackageDetails packageDetails) {
    DeployPackagesResponse response = new DeployPackagesResponse(ContentResponseResult.FAILURE);

    DeployIndividualPackageResponse packageResponse =
        new DeployIndividualPackageResponse(packageDetails.getKey(), ContentResponseResult.FAILURE);
    packageResponse.setErrorMessage(errorMessage);

    response.addPackageResponse(packageResponse);

    return response;
  }
Esempio n. 2
0
  public DeployPackagesResponse deployPackages(
      Set<ResourcePackageDetails> packages, ContentServices contentServices) {
    DeployPackagesResponse response = new DeployPackagesResponse();
    if (packages.size() != 1) {
      log.warn(
          "Request to deploy a script containing multiple files, which is obivously illegal: "
              + packages);
      response.setOverallRequestResult(ContentResponseResult.FAILURE);
      response.setOverallRequestErrorMessage("Only one script can be updated at a time.");
      return response;
    }

    try {
      String jbossHomeDir =
          resourceContext
              .getParentResourceComponent()
              .getResourceContext()
              .getPluginConfiguration()
              .getSimpleValue(ApplicationServerPluginConfigurationProperties.HOME_DIR, null);
      SystemInfo systemInfo = resourceContext.getSystemInformation();
      ProfileServiceConnection profileServiceConnection =
          resourceContext.getParentResourceComponent().getConnection();

      ScriptDeployer deployer =
          new ScriptDeployer(
              jbossHomeDir,
              systemInfo,
              new RemoteDownloader(resourceContext, true, profileServiceConnection));
      ResourcePackageDetails packageDetails = packages.iterator().next();

      DeployIndividualPackageResponse scriptUpdateResult =
          deployer.update(packageDetails, resourceContext.getResourceType());

      response.setOverallRequestResult(scriptUpdateResult.getResult());
      response.addPackageResponse(scriptUpdateResult);
    } catch (Exception e) {
      response.setOverallRequestErrorMessage(e.getMessage());
      response.setOverallRequestResult(ContentResponseResult.FAILURE);
    }

    return response;
  }
Esempio n. 3
0
  @Override
  public DeployPackagesResponse deployPackages(
      Set<ResourcePackageDetails> packages, ContentServices contentServices) {
    // You can only update the one application file referenced by this
    // resource, so punch out if multiple are
    // specified.
    if (packages.size() != 1) {
      log.warn(
          "Request to update a VDB file contained multiple packages: " //$NON-NLS-1$
              + packages);
      DeployPackagesResponse response = new DeployPackagesResponse(ContentResponseResult.FAILURE);
      response.setOverallRequestErrorMessage(
          "When updating a VDB, only one VDB can be updated at a time."); //$NON-NLS-1$
      return response;
    }

    ResourcePackageDetails packageDetails = packages.iterator().next();

    log.debug(
        "Updating VDB file '"
            + this.deploymentFile
            + "' using [" //$NON-NLS-1$ //$NON-NLS-2$
            + packageDetails
            + "]..."); //$NON-NLS-1$

    log.debug("Writing new VDB bits to temporary file..."); // $NON-NLS-1$
    File tempFile;
    try {
      tempFile = writeNewAppBitsToTempFile(contentServices, packageDetails);
    } catch (Exception e) {
      return failApplicationDeployment(
          "Error writing new application bits to temporary file - cause: " //$NON-NLS-1$
              + e,
          packageDetails);
    }
    log.debug(
        "Wrote new VDB bits to temporary file '"
            + tempFile //$NON-NLS-1$
            + "'."); //$NON-NLS-1$

    boolean deployExploded = this.deploymentFile.isDirectory();

    // Backup the original app file/dir to <filename>.rej.
    File backupOfOriginalFile = new File(this.deploymentFile.getPath() + BACKUP_FILE_EXTENSION);
    log.debug(
        "Backing up existing VDB '"
            + this.deploymentFile // $NON-NLS-1$
            + "' to '"
            + backupOfOriginalFile
            + "'..."); //$NON-NLS-1$ //$NON-NLS-2$
    try {
      if (backupOfOriginalFile.exists()) FileUtils.forceDelete(backupOfOriginalFile);
      if (this.deploymentFile.isDirectory())
        FileUtils.copyDirectory(this.deploymentFile, backupOfOriginalFile, true);
      else FileUtils.copyFile(this.deploymentFile, backupOfOriginalFile, true);
    } catch (Exception e) {
      throw new RuntimeException(
          "Failed to backup existing EAR/WAR '" //$NON-NLS-1$
              + this.deploymentFile
              + "' to '"
              + backupOfOriginalFile //$NON-NLS-1$
              + "'."); //$NON-NLS-1$
    }

    // Now stop the original app.
    try {
      DeploymentManager deploymentManager = getConnection().getDeploymentManager();
      DeploymentProgress progress = deploymentManager.stop(this.deploymentUrl);
      DeploymentUtils.run(progress);
    } catch (Exception e) {
      throw new RuntimeException(
          "Failed to stop deployment [" //$NON-NLS-1$
              + this.deploymentUrl
              + "].",
          e); //$NON-NLS-1$
    }

    // And then remove it (this will delete the physical file/dir from the
    // deploy dir).
    try {
      DeploymentManager deploymentManager = getConnection().getDeploymentManager();
      DeploymentProgress progress = deploymentManager.remove(this.deploymentUrl);
      DeploymentUtils.run(progress);
    } catch (Exception e) {
      throw new RuntimeException(
          "Failed to remove deployment [" //$NON-NLS-1$
              + this.deploymentUrl
              + "].",
          e); //$NON-NLS-1$
    }

    // Deploy away!
    log.debug("Deploying '" + tempFile + "'..."); // $NON-NLS-1$ //$NON-NLS-2$
    DeploymentManager deploymentManager = getConnection().getDeploymentManager();
    try {
      DeploymentUtils.deployArchive(deploymentManager, tempFile, deployExploded);
    } catch (Exception e) {
      // Deploy failed - rollback to the original app file...
      log.debug(
          "Redeploy failed - rolling back to original archive...", //$NON-NLS-1$
          e);
      String errorMessage = ThrowableUtil.getAllMessages(e);
      try {
        // Delete the new app, which failed to deploy.
        FileUtils.forceDelete(this.deploymentFile);
        // Need to re-deploy the original file - this generally should
        // succeed.
        DeploymentUtils.deployArchive(deploymentManager, backupOfOriginalFile, deployExploded);
        errorMessage += " ***** ROLLED BACK TO ORIGINAL APPLICATION FILE. *****"; // $NON-NLS-1$
      } catch (Exception e1) {
        log.debug("Rollback failed!", e1); // $NON-NLS-1$
        errorMessage +=
            " ***** FAILED TO ROLLBACK TO ORIGINAL APPLICATION FILE. *****: " //$NON-NLS-1$
                + ThrowableUtil.getAllMessages(e1);
      }
      log.info(
          "Failed to update VDB file '"
              + this.deploymentFile // $NON-NLS-1$
              + "' using ["
              + packageDetails
              + "]."); //$NON-NLS-1$ //$NON-NLS-2$
      return failApplicationDeployment(errorMessage, packageDetails);
    }

    // Deploy was successful!

    deleteBackupOfOriginalFile(backupOfOriginalFile);
    persistApplicationVersion(packageDetails, this.deploymentFile);

    DeployPackagesResponse response = new DeployPackagesResponse(ContentResponseResult.SUCCESS);
    DeployIndividualPackageResponse packageResponse =
        new DeployIndividualPackageResponse(packageDetails.getKey(), ContentResponseResult.SUCCESS);
    response.addPackageResponse(packageResponse);

    log.debug(
        "Updated VDB file '"
            + this.deploymentFile // $NON-NLS-1$
            + "' successfully - returning response ["
            + response
            + "]..."); //$NON-NLS-1$ //$NON-NLS-2$

    return response;
  }