/** * Add and initialize a new Deployer to deployment engine. * * @param deployer the deployer instance to register * @throws org.wso2.carbon.deployment.exception.DeployerRegistrationException Throwing deployment * registration exception */ public void registerDeployer(Deployer deployer) throws DeployerRegistrationException { if (deployer == null) { throw new DeployerRegistrationException( "Failed to add Deployer : " + "Deployer Class Name is null"); } // Try and initialize the deployer deployer.init(); if (deployer.getLocation() == null) { throw new DeployerRegistrationException( "Failed to add Deployer " + deployer.getClass().getName() + ": missing 'directory' attribute " + "in deployer instance"); } ArtifactType type = deployer.getArtifactType(); if (type == null) { throw new DeployerRegistrationException( "Artifact Type for Deployer : " + deployer + " is null"); } Deployer existingDeployer = deployerMap.get(type); if (existingDeployer == null) { deployerMap.put(type, deployer); } }
/** * Undeploy the artifacts found in the artifact to be undeployed list * * @param artifactsToUndeploy list of artifacts to undeploy */ public void undeployArtifacts(List<Artifact> artifactsToUndeploy) { for (Object artifact : artifactsToUndeploy) { Artifact artifactToUnDeploy = (Artifact) artifact; try { Deployer deployer = getDeployer(artifactToUnDeploy.getType()); if (deployer != null) { deployer.undeploy(artifactToUnDeploy.getKey()); removeFromDeployedArtifacts(artifactToUnDeploy); } else { throw new CarbonDeploymentException( "Deployer instance cannot be found for " + "the type : " + artifactToUnDeploy.getType()); } } catch (CarbonDeploymentException e) { logger.error("Error while undeploying artifacts", e); } } }
/** * Removes a deployer from the deployment engine configuration * * @param deployer the deployer instance to un-register * @throws DeploymentEngineException Throwing deployment registration exception */ public void unregisterDeployer(Deployer deployer) throws DeploymentEngineException { ArtifactType type = deployer.getArtifactType(); if (type == null) { throw new DeploymentEngineException("Artifact Type for Deployer : " + deployer + " is null"); } Deployer existingDeployer = deployerMap.get(type); if (existingDeployer != null) { deployerMap.remove(type); } }
/** * Updates the artifacts found in the artifacts to be updated list * * @param artifactsToUpdate list of artifacts to update */ public void updateArtifacts(List<Artifact> artifactsToUpdate) { for (Object artifact : artifactsToUpdate) { Artifact artifactToUpdate = (Artifact) artifact; try { Deployer deployer = getDeployer(artifactToUpdate.getType()); if (deployer != null) { Object artifactKey = deployer.update(artifactToUpdate); artifactToUpdate.setKey(artifactKey); addToDeployedArtifacts(artifactToUpdate); } else { throw new CarbonDeploymentException( "Deployer instance cannot be found for " + "the type : " + artifactToUpdate.getType()); } } catch (CarbonDeploymentException e) { // TODO : Handle faulty artifact deployment logger.error("Error while updating artifacts", e); } } }