Package org.jboss.deployers.spi.management.deploy

Examples of org.jboss.deployers.spi.management.deploy.DeploymentManager


        Configuration pluginConfiguration = getResourceContext().getPluginConfiguration();
        String fullFileName = pluginConfiguration.getSimple("deployment").getStringValue();
       
        ESB5Component jbossASComponent = (ESB5Component) getResourceContext().getParentResourceComponent();
        ProfileServiceConnection profileServiceConnection = jbossASComponent.getConnection();
        DeploymentManager deployMgr = profileServiceConnection.getDeploymentManager();

        String repositoryName = null;
        String [] arr = deployMgr.getRepositoryNames(new String[] {fullFileName});
        for (int i = 0; i<arr.length; i++) {
          repositoryName = arr[i];
        }
       
        if (repositoryName != null) {
          DeploymentProgress stop   = null;
          try {
            stop = deployMgr.stop(repositoryName);
              if (stop != null)
                stop.run();
          } catch (Throwable t) {
            log.error("Could not find deployment to delete.  " + t.getMessage());  
            return;
          } finally {
              jbossASComponent.disconnectFromProfileService();
          }

          DeploymentStatus stopStatus = stop.getDeploymentStatus();         
          if (stopStatus.isFailed()) {
           
            if ((stopStatus.getFailure() != null) && (stopStatus.getFailure().getCause() != null)
                && (stopStatus.getFailure().getCause() instanceof java.lang.NullPointerException)) {                   
              // jon 2.3 case
              // If we get a NPE here, it means that the .esb deployment has already been deleted
                  // Return here because otherwise JON will not update and remove the deployment
                  log.error("Failed to stop deployment '" + repositoryName + "'.", stopStatus.getFailure());
                  jbossASComponent.disconnectFromProfileService();

                  return;
              } else if ((stopStatus.getFailure().getCause() != null)
                && (stopStatus.getFailure().getCause() instanceof org.jboss.profileservice.spi.NoSuchDeploymentException)) {
                  // jon 2.4 case
                // If we get a NPE here, it means that the .esb deployment has already been deleted
                  // Return here because otherwise JON will not update and remove the deployment
                  log.error("Failed to stop deployment '" + repositoryName + "'.", stopStatus.getFailure());
                  jbossASComponent.disconnectFromProfileService();
     
                  return;
              }
              log.error("Failed to stop deployment '" + repositoryName + "'.", stopStatus.getFailure());
              throw new Exception("Failed to stop deployment '" + repositoryName + "' - cause: "
                  + stopStatus.getFailure());
          }       
            DeploymentProgress remove = deployMgr.remove(repositoryName);       
            if (remove != null) {
                remove.run();
              DeploymentStatus status = remove.getDeploymentStatus();
              if (status.isFailed()) {
                log.error("Failed to remove deployment '" + repositoryName + "'.", status.getFailure());
View Full Code Here


        log.debug("Connecting to Profile Service via remote JNDI using env [" + env + "]...");
        this.initialContext = createInitialContext(env);

        ProfileService profileService = (ProfileService) lookup(this.initialContext, PROFILE_SERVICE_JNDI_NAME);
        ManagementView managementView = (ManagementView) lookup(this.initialContext, MANAGEMENT_VIEW_JNDI_NAME);
        DeploymentManager deploymentManager = (DeploymentManager) lookup(this.initialContext,
                DEPLOYMENT_MANAGER_JNDI_NAME);

        AbstractProfileServiceConnection profileServiceConnection;
        if (this.principal != null) {
            // Use a connection that will perform a JAAS login prior to all invocations.
View Full Code Here

    protected BasicProfileServiceConnection doConnect() {
        log.debug("Connecting to Profile Service via local JNDI...");
        InitialContext initialContext = createInitialContext(null);
        ProfileService profileService = (ProfileService) lookup(initialContext, PROFILE_SERVICE_LOCAL_JNDI_NAME);
        ManagementView managementView = profileService.getViewManager();
        DeploymentManager deploymentManager = profileService.getDeploymentManager();
        return new BasicProfileServiceConnection(this, profileService, managementView, deploymentManager);
    }
View Full Code Here

    }
   
    public void init() {
        ManagementView managementView = getManagementView();
        managementView.load();
        DeploymentManager deploymentManager = getDeploymentManager();
        // Load and associate the given profile with the DeploymentManager for future operations. This is mandatory
        // in order for us to be able to successfully invoke the various DeploymentManager methods.
        try {
            deploymentManager.loadProfile(DEFAULT_PROFILE_KEY);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

            DeployPackagesResponse response = new DeployPackagesResponse(ContentResponseResult.FAILURE);
            response.setOverallRequestErrorMessage("No profile service connection available");
            return response;
        }

        DeploymentManager deploymentManager = connection.getDeploymentManager();

        // as crazy as it might sound, there is apparently no way for you to ask the profile service
        // if a deployment was deployed to the farm profile. Thus, we must resort to a poor man's solution:
        // if the deployment name has the "farm/" directory in it, assume it needs to be deployed to the farm
        boolean deployFarmed = getDeploymentKey().contains("/farm/");
        if (deployFarmed) {
            Collection<ProfileKey> profileKeys = deploymentManager.getProfiles();
            boolean farmSupported = false;
            for (ProfileKey profileKey : profileKeys) {
                if (profileKey.getName().equals(FARM_PROFILE_KEY.getName())) {
                    farmSupported = true;
                    break;
                }
            }
            if (!farmSupported) {
                throw new IllegalStateException("This application server instance is not a node in a cluster, "
                    + "so it does not support farmed deployments. Supported deployment profiles are " + profileKeys
                    + ".");
            }
            if (deployExploded) {
                throw new IllegalArgumentException(
                    "Deploying farmed applications in exploded form is not supported by the Profile Service.");
            }
            try {
                deploymentManager.loadProfile(FARM_PROFILE_KEY);
            } catch (Exception e) {
                LOG.info("Failed to switch to farm profile - could not update " + resourceTypeName + " file '"
                    + deploymentFile + "' using [" + packageDetails + "].");
                String errorMessage = ThrowableUtil.getAllMessages(e);
                return failApplicationDeployment(errorMessage, packageDetails);
            }
        }

        String deploymentName = getDeploymentName();
        if (deploymentName == null) {
            DeployPackagesResponse response = new DeployPackagesResponse(ContentResponseResult.FAILURE);
            response.setOverallRequestErrorMessage("Did not find deployment with key [" + getDeploymentKey() + "]");
            return response;
        }

        // Now stop the original app.
        try {
            DeploymentProgress progress = deploymentManager.stop(deploymentName);
            DeploymentUtils.run(progress);
        } catch (Exception e) {
            throw new RuntimeException("Failed to stop deployment [" + deploymentName + "].", e);
        }

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

        // Deploy away!
        try {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Deploying '" + tempFile + "'...");
            }
            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...", e);
            String errorMessage = ThrowableUtil.getAllMessages(e);
            try {
                // Try to delete the new app file, which failed to deploy, if it still exists.
                if (deploymentFile.exists()) {
                    try {
                        FileUtils.forceDelete(deploymentFile);
                    } catch (IOException e1) {
                        if (LOG.isDebugEnabled()) {
                            LOG.debug("Failed to delete application file '" + deploymentFile
                                + "' that failed to deploy.", e1);
                        }
                    }
                }
                // Now redeploy the original file - this generally should succeed.
                DeploymentUtils.deployArchive(deploymentManager, backupOfOriginalFile, deployExploded);
                errorMessage += " ***** ROLLED BACK TO ORIGINAL APPLICATION FILE. *****";

                // If the redeployment of the original backup succeeded then cleanup the backup from disk
                deleteTemporaryFile(backupDir);
                // If the redeployment fails the original backup is preserved on disk until agent restart
            } catch (Exception e1) {
                LOG.debug("Rollback failed!", e1);
                errorMessage += " ***** FAILED TO ROLLBACK TO ORIGINAL APPLICATION FILE. *****: "
                    + ThrowableUtil.getAllMessages(e1);
            }

            //since the deployment failed remove the temp application downloaded for deployment
            deleteTemporaryFile(tempFile);

            LOG.info("Failed to update " + resourceTypeName + " file '" + deploymentFile + "' using [" + packageDetails
                + "].");
            return failApplicationDeployment(errorMessage, packageDetails);
        } finally {
            // Make sure to switch back to the 'applications' profile if we switched to the 'farm' profile above.
            if (deployFarmed) {
                try {
                    deploymentManager.loadProfile(APPLICATIONS_PROFILE_KEY);
                } catch (Exception e) {
                    LOG.debug("Failed to switch back to applications profile from farm profile", e);
                }
            }
        }
View Full Code Here

        ProfileServiceConnection connection = getConnection();
        if (connection == null) {
            throw new Exception("No profile service connection available");
        }

        DeploymentManager deploymentManager = connection.getDeploymentManager();
        try {
            getManagedDeployment();
        } catch (Exception e) {
            // The deployment no longer exists, so there's nothing for us to do. Someone most likely undeployed it
            // outside of Jopr or EmbJopr, e.g. via the jmx-console or by deleting the app file from the deploy dir.
            LOG.warn("Cannot delete the deployment [" + getDeploymentKey() + "], since it no longer exists");
            return;
        }

        if (LOG.isDebugEnabled()) {
            LOG.debug("Stopping deployment [" + getDeploymentKey() + "]...");
        }

        String deploymentName = getDeploymentName();
        if (deploymentName == null) {
            throw new IllegalStateException("Deployment " + getDeploymentKey() + " has vanished");
        }

        DeploymentProgress progress = deploymentManager.stop(deploymentName);
        DeploymentStatus stopStatus = DeploymentUtils.run(progress);
        if (stopStatus.isFailed()) {
            LOG.error("Failed to stop deployment '" + deploymentName + "'.", stopStatus.getFailure());
            throw new Exception("Failed to stop deployment '" + deploymentName + "' - cause: "
                + stopStatus.getFailure());
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug("Removing deployment [" + deploymentName + "]...");
        }
        progress = deploymentManager.remove(deploymentName);
        DeploymentStatus removeStatus = DeploymentUtils.run(progress);
        if (removeStatus.isFailed()) {
            LOG.error("Failed to remove deployment '" + deploymentName + "'.", removeStatus.getFailure());
            throw new Exception("Failed to remove deployment '" + deploymentName + "' - cause: "
                + removeStatus.getFailure());
View Full Code Here

    // DeleteResourceFacet Implementation  --------------------------------------------

    @Override
    public void deleteResource() throws Exception {
        DeploymentManager deploymentManager = getConnection().getDeploymentManager();
        if (!deploymentManager.isRedeploySupported())
            throw new UnsupportedOperationException("Deletion of " + getResourceContext().getResourceType().getName()
                + " Resources is not currently supported.");
        ManagedComponent managedComponent = getManagedComponent();
        if (LOG.isDebugEnabled()) {
            LOG.debug("Removing " + getResourceDescription() + " with component " + toString(managedComponent) + "...");
        }
        ManagementView managementView = getConnection().getManagementView();
        managementView.removeComponent(managedComponent);
        ManagedDeployment parentDeployment = managedComponent.getDeployment();

        if (parentDeployment.getComponents().size() > 1 || !parentDeployment.getChildren().isEmpty()) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Redeploying parent deployment '" + parentDeployment.getName()
                    + "' in order to complete removal of component " + toString(managedComponent) + "...");
            }
            DeploymentProgress progress = deploymentManager.redeploy(parentDeployment.getName());
            DeploymentStatus status = DeploymentUtils.run(progress);
            if (status.isFailed()) {
                LOG.error("Failed to redeploy parent deployment '" + parentDeployment.getName()
                    + "during removal of component " + toString(managedComponent)
                    + " - removal may not persist when the app server is restarted.", status.getFailure());
            }
        } else {
            //this is the last component of the deployment and nothing would be left there after
            //the component was removed. Let's just undeploy it in addition to removing the component.
            //This will make sure that the deployment doesn't leave behind any defunct config files, etc.
            if (LOG.isDebugEnabled()) {
                LOG.debug("Undeploying parent deployment '" + parentDeployment.getName()
                    + "' in order to complete removal of component " + toString(managedComponent) + "...");
            }
            parentDeployment = managementView.getDeployment(parentDeployment.getName());
            DeploymentProgress progress = deploymentManager.remove(parentDeployment.getName());
            DeploymentStatus status = DeploymentUtils.run(progress);
            if (status.isFailed()) {
                LOG.error("Failed to undeploy parent deployment '" + parentDeployment.getName()
                    + "during removal of component " + toString(managedComponent)
                    + " - removal may not persist when the app server is restarted.", status.getFailure());
View Full Code Here

     * @param archiveFile the archive file
     * @param exploded whether to deploy exploded or not
     * @throws Exception
     */
    public static void deployFileToAS(String name, File archiveFile, boolean exploded) throws Exception {
        DeploymentManager deploymentManager = getDeploymentManager();

        DeploymentProgress progress = deploymentManager.distribute(name, archiveFile.toURI().toURL(), exploded);
        progress.run();

        DeploymentStatus status = progress.getDeploymentStatus();

        if (status.isFailed()) {
            throw new IllegalStateException("Failed to distribute " + archiveFile.getAbsolutePath() + " with message: "
                + status.getMessage());
        }

        String[] deploymentNames = progress.getDeploymentID().getRepositoryNames();

        progress = deploymentManager.start(deploymentNames);
        progress.run();

        status = progress.getDeploymentStatus();

        if (status.isFailed()) {
View Full Code Here

     *
     * @param archiveName
     * @throws Exception
     */
    public static void undeployFromAS(String archiveName) throws Exception {
        DeploymentManager deploymentManager = getDeploymentManager();

       
        DeploymentProgress progress = deploymentManager.stop(archiveName);
        progress.run();

        DeploymentStatus status = progress.getDeploymentStatus();

        if (status.isFailed()) {
            throw new IllegalStateException("Failed to stop " + archiveName + " with message: "
                + status.getMessage());
        }

        progress = deploymentManager.remove(archiveName);
        progress.run();

        status = progress.getDeploymentStatus();

        if (status.isFailed()) {
View Full Code Here

            abortIfApplicationAlreadyDeployed(resourceType, archiveFile);

            Configuration deployTimeConfig = details.getDeploymentTimeConfiguration();
            boolean deployExploded = deployTimeConfig.getSimple("deployExploded").getBooleanValue();

            DeploymentManager deploymentManager = this.profileServiceConnection.getDeploymentManager();
            boolean deployFarmed = deployTimeConfig.getSimple("deployFarmed").getBooleanValue();
            if (deployFarmed) {
                Collection<ProfileKey> profileKeys = deploymentManager.getProfiles();
                boolean farmSupported = false;
                for (ProfileKey profileKey : profileKeys) {
                    if (profileKey.getName().equals(FARM_PROFILE_KEY.getName())) {
                        farmSupported = true;
                        break;
                    }
                }
                if (!farmSupported) {
                    throw new IllegalStateException("This application server instance is not a node in a cluster, "
                        + "so it does not support farmed deployments. Supported deployment profiles are " + profileKeys
                        + ".");
                }
                if (deployExploded) {
                    throw new IllegalArgumentException(
                        "Deploying farmed applications in exploded form is not supported by the Profile Service.");
                }
                deploymentManager.loadProfile(FARM_PROFILE_KEY);
            }

            String[] deploymentNames;
            try {
                deploymentNames = DeploymentUtils.deployArchive(deploymentManager, archiveFile, deployExploded);
            } finally {
                // Make sure to switch back to the 'applications' profile if we switched to the 'farm' profile above.
                if (deployFarmed) {
                    deploymentManager.loadProfile(APPLICATIONS_PROFILE_KEY);
                }
            }

            if (deploymentNames == null || deploymentNames.length != 1) {
                throw new RuntimeException("deploy operation returned invalid result: " + deploymentNames);
View Full Code Here

TOP

Related Classes of org.jboss.deployers.spi.management.deploy.DeploymentManager

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.