Package org.rhq.core.domain.content.transfer

Examples of org.rhq.core.domain.content.transfer.DeployPackagesResponse


    // 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;
View Full Code Here


   *            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;
  }
View Full Code Here

            if (packageTypeName.equals(PACKAGE_TYPE_PATCH)) {

                if (packages.size() > 1) {
                    log.warn("Attempt to install more than one patch at a time, installation aborted.");

                    DeployPackagesResponse response = new DeployPackagesResponse(ContentResponseResult.FAILURE);
                    response
                        .setOverallRequestErrorMessage("When deploying a patch, no other packages may be deployed at the same time.");
                    return response;
                }

                try {
                    DeployIndividualPackageResponse response = getWorkflowManager().run(pkg);

                    if (response.getResult() == ContentResponseResult.FAILURE) {
                        overallResult = ContentResponseResult.FAILURE;
                    }

                    // just in case response is null, it would throw NPE on the getResult() check above but the item
                    // would already be a member in individualResponses; moving the add below the check ensures that
                    // only non-null instances of individualResponses will ever make it into the List
                    individualResponses.add(response);
                } catch (Throwable throwable) {
                    log.error("Error deploying package: " + pkg, throwable);

                    // Don't forget to provide an individual response for the failed package.
                    DeployIndividualPackageResponse response = new DeployIndividualPackageResponse(pkg.getKey(),
                        ContentResponseResult.FAILURE);
                    response.setErrorMessageFromThrowable(throwable);
                    individualResponses.add(response);

                    overallResult = ContentResponseResult.FAILURE;
                }
            } else if (packageTypeName.equals(PACKAGE_TYPE_LIBRARY)) {
                if (packages.size() > 1) {
                    log.warn("Attempt to install more than one patch at a time, installation aborted.");

                    DeployPackagesResponse response = new DeployPackagesResponse(ContentResponseResult.FAILURE);
                    response
                        .setOverallRequestErrorMessage("When deploying a patch, no other packages may be deployed at the same time.");
                    return response;
                } else {
                    deployJarLibrary(pkg, contentServices);
                }
            }
        }

        DeployPackagesResponse response = new DeployPackagesResponse(overallResult);
        response.getPackageResponses().addAll(individualResponses);

        return response;
    }
View Full Code Here

            response.setErrorMessageFromThrowable(throwable);
            individualResponses.add(response);
            overallResult = ContentResponseResult.FAILURE;
        }

        DeployPackagesResponse response = new DeployPackagesResponse(overallResult);
        response.getPackageResponses().addAll(individualResponses);
        return response;
    }
View Full Code Here

            if (packageTypeName.equals(PACKAGE_TYPE_LIBRARY)) {
                throw new UnsupportedOperationException("Deployment of new libraries is not supported by the plugin.");
            }
        }

        DeployPackagesResponse response = new DeployPackagesResponse(overallResult);
        response.getPackageResponses().addAll(individualResponses);

        return response;
  }
View Full Code Here

            if (packageTypeName.equals(PACKAGE_TYPE_LIBRARY)) {
                throw new UnsupportedOperationException("Deployment of new libraries is not supported by the plugin.");
            }
        }

        DeployPackagesResponse response = new DeployPackagesResponse(overallResult);
        response.getPackageResponses().addAll(individualResponses);

        return response;
  }
View Full Code Here

            }

            Runnable responseRunner = new Runnable() {
                public void run() {
                    synchronized (responseLock) {
                        DeployPackagesResponse response = new DeployPackagesResponse(responseReturnStatus);

                        // This setting of the ID will be done by the plugin container; we're not relying on the plugin
                        // to do it. Since I'm skipping the PC entirely for this test, I'll do it here.
                        response.setRequestId(request.getRequestId());

                        if (returnIndividualResponses) {
                            for (ResourcePackageDetails packageDetails : request.getPackages()) {
                                DeployIndividualPackageResponse individualResponse = new DeployIndividualPackageResponse(
                                    packageDetails.getKey(), responseReturnStatus);

                                individualResponse.setDeploymentSteps(deployPackageSteps);

                                response.addPackageResponse(individualResponse);
                            }
                        }

                        ContentManagerBeanTest.this.contentManager.completeDeployPackageRequest(response);
                    }
View Full Code Here

     */
    DeployPackagesResponse performPackageDeployment(int resourceId, Set<ResourcePackageDetails> packagesToDeploy)
        throws Exception {
        // Perform the create
        ContentFacet contentFacet = findContentFacet(resourceId);
        DeployPackagesResponse response = contentFacet.deployPackages(packagesToDeploy, this);

        return response;
    }
View Full Code Here

    // Callable Implementation  --------------------------------------------

    public DeployPackagesResponse call() throws Exception {

        DeployPackagesResponse response;

        try {
            response = contentManager.performPackageDeployment(request.getResourceId(), request.getPackages());
        } catch (Throwable throwable) {
            response = new DeployPackagesResponse(ContentResponseResult.FAILURE);
            response.setOverallRequestErrorMessage(ThrowableUtil.getStackAsString(throwable));
        }

        // We don't rely on the plugin to map up the response to the request ID, so we do it here
        response.setRequestId(request.getRequestId());

        // Request a new discovery so this package is put in the inventory for the resource.
        Set<DeployIndividualPackageResponse> packageResponses = response.getPackageResponses();
        if (packageResponses != null) {

            // Keep a quick cache of which package types have had discoveries executed so we don't
            // unnecessarily hammer the plugin with redundant discoveries
            Set<String> packageTypeNames = new HashSet<String>();

            for (DeployIndividualPackageResponse individualResponse : packageResponses) {
                PackageDetailsKey key = individualResponse.getKey();

                if (key == null)
                    continue;

                String packageTypeName = key.getPackageTypeName();

                // Make sure we haven't already run a discovery for this package type
                if (!packageTypeNames.contains(packageTypeName)) {
                    packageTypeNames.add(packageTypeName);

                    try {
                        contentManager.executeResourcePackageDiscoveryImmediately(request.getResourceId(),
                            individualResponse.getKey().getPackageTypeName());
                    } catch (Throwable throwable) {
                        log.error("Error occurred on content discovery request" + throwable);
                    }
                }
            }
        }

        // Contact the server service if one exists
        ContentServerService serverService = contentManager.getContentServerService();
        if (serverService != null) {
            serverService.completeDeployPackageRequest(response);
        }

        // Trigger a resource discovery to pick up on any potential changes to the resource that occurred by
        // this package deployment
        if (response.getOverallRequestResult() == ContentResponseResult.SUCCESS) {

            try {
                ResourceType resourceType = ComponentUtil.getResourceType(request.getResourceId());
                InventoryManager inventoryManager = contentManager.getInventoryManager();
View Full Code Here

            if (packageTypeName.equals(PACKAGE_TYPE_PATCH)) {

                if (packages.size() > 1) {
                    log.warn("Attempt to install more than one patch at a time, installation aborted.");

                    DeployPackagesResponse response = new DeployPackagesResponse(ContentResponseResult.FAILURE);
                    response
                        .setOverallRequestErrorMessage("When deploying a patch, no other packages may be deployed at the same time.");
                    return response;
                }

                try {
                    DeployIndividualPackageResponse response = workflowManager.run(pkg);

                    if (response.getResult() == ContentResponseResult.FAILURE) {
                        overallResult = ContentResponseResult.FAILURE;
                    }
                   
                    // just in case response is null, it would throw NPE on the getResult() check above but the item
                    // would already be a member in individualResponses; moving the add below the check ensures that
                    // only non-null instances of individualResponses will ever make it into the List
                    individualResponses.add(response);
                } catch (Throwable throwable) {
                    log.error("Error deploying package: " + pkg, throwable);

                    // Don't forget to provide an individual response for the failed package.
                    DeployIndividualPackageResponse response = new DeployIndividualPackageResponse(pkg.getKey(),
                        ContentResponseResult.FAILURE);
                    response.setErrorMessage(ThrowableUtil.getStackAsString(throwable));
                    individualResponses.add(response);

                    overallResult = ContentResponseResult.FAILURE;
                }
            } else if (packageTypeName.equals(PACKAGE_TYPE_LIBRARY)) {
                throw new UnsupportedOperationException("Deployment of new libraries is not supported by the plugin.");
            }
        }

        DeployPackagesResponse response = new DeployPackagesResponse(overallResult);
        response.getPackageResponses().addAll(individualResponses);

        return response;
    }
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.content.transfer.DeployPackagesResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.