use of org.craftercms.studio.api.v2.deployment.Deployer in project carbon-mediation by wso2.
the class SynapseAppDeployer method deployClassMediators.
/**
* Deploy class mediators contains in the CApp
*
* @param artifacts List of Artifacts contains in the capp
* @param axisConfig AxisConfiguration of the current tenant
* @throws DeploymentException if something goes wrong while deployment
*/
private void deployClassMediators(List<Artifact.Dependency> artifacts, AxisConfiguration axisConfig) throws DeploymentException {
for (Artifact.Dependency dependency : artifacts) {
Artifact artifact = dependency.getArtifact();
if (!validateArtifact(artifact)) {
continue;
}
if (SynapseAppDeployerConstants.MEDIATOR_TYPE.endsWith(artifact.getType())) {
Deployer deployer = getClassMediatorDeployer(axisConfig);
if (deployer != null) {
artifact.setRuntimeObjectName(artifact.getName());
String fileName = artifact.getFiles().get(0).getName();
String artifactPath = artifact.getExtractedPath() + File.separator + fileName;
try {
deployer.deploy(new DeploymentFileData(new File(artifactPath), deployer));
artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_DEPLOYED);
} catch (DeploymentException e) {
artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_FAILED);
throw e;
}
}
}
}
}
use of org.craftercms.studio.api.v2.deployment.Deployer in project carbon-mediation by wso2.
the class SynapseAppDeployer method getDeployer.
/**
* Finds the correct deployer for the given artifact type
*
* @param axisConfig - AxisConfiguration instance
* @return Deployer instance
*/
private Deployer getDeployer(AxisConfiguration axisConfig, String directory) {
Deployer deployer = null;
// access the deployment engine through axis config
DeploymentEngine deploymentEngine = (DeploymentEngine) axisConfig.getConfigurator();
String tenantId = AppDeployerUtils.getTenantIdString(axisConfig);
SynapseEnvironmentService environmentService = DataHolder.getInstance().getSynapseEnvironmentService(Integer.parseInt(tenantId));
if (environmentService != null) {
String synapseConfigPath = ServiceBusUtils.getSynapseConfigAbsPath(environmentService.getSynapseEnvironment().getServerContextInformation());
String endpointDirPath = synapseConfigPath + File.separator + directory;
deployer = deploymentEngine.getDeployer(endpointDirPath, ServiceBusConstants.ARTIFACT_EXTENSION);
}
return deployer;
}
use of org.craftercms.studio.api.v2.deployment.Deployer in project carbon-mediation by wso2.
the class SynapseAppDeployer method deployArtifactType.
/**
* This deploys artifacts when a list of artifacts is provided
*
* @param artifacts - List of artifacts which should be deployed
* @param carbonApp - CarbonApplication instance to check for artifacts
* @param axisConfig - AxisConfiguration of the current tenant
* @throws DeploymentException if some error occurs while deployment
*/
public void deployArtifactType(List<Artifact.Dependency> artifacts, CarbonApplication carbonApp, AxisConfiguration axisConfig) throws DeploymentException {
for (Artifact.Dependency dep : artifacts) {
Artifact artifact = dep.getArtifact();
String artifactDirName = getArtifactDirName(artifact);
if (!validateArtifact(artifact) || artifactDirName == null) {
continue;
}
Deployer deployer = getDeployer(axisConfig, artifactDirName);
String artifactDir = getArtifactDirPath(axisConfig, artifactDirName);
artifact.setRuntimeObjectName(artifact.getName());
if (deployer != null) {
String fileName = artifact.getFiles().get(0).getName();
String artifactPath = artifact.getExtractedPath() + File.separator + fileName;
File artifactInRepo = new File(artifactDir + File.separator + fileName);
if (SynapseAppDeployerConstants.SEQUENCE_TYPE.equals(artifact.getType()) && handleMainFaultSeqDeployment(artifact, axisConfig)) {
} else if (artifactInRepo.exists()) {
log.warn("Artifact " + fileName + " already found in " + artifactInRepo.getAbsolutePath() + ". Ignoring CAPP's artifact");
artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_DEPLOYED);
} else {
try {
setCustomLogContent(deployer, carbonApp);
deployer.deploy(new DeploymentFileData(new File(artifactPath), deployer));
artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_DEPLOYED);
} catch (Throwable e) {
artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_FAILED);
if (!(e instanceof DeploymentException)) {
throw new DeploymentException(e);
} else {
throw e;
}
} finally {
// clear the log appender once deployment is finished to avoid appending the
// same log to other classes.
setCustomLogContent(deployer, null);
CustomLogSetter.getInstance().clearThreadLocalContent();
}
}
}
}
}
use of org.craftercms.studio.api.v2.deployment.Deployer in project carbon-mediation by wso2.
the class SynapseAppDeployer method deploySynapseLibrary.
/**
* Deploy synapse libraries contains in the CApp
*
* @param artifacts List of Artifacts contains in the capp
* @param axisConfig AxisConfiguration of the current tenant
* @throws DeploymentException if something goes wrong while deployment
*/
private void deploySynapseLibrary(List<Artifact.Dependency> artifacts, AxisConfiguration axisConfig) throws DeploymentException {
for (Artifact.Dependency dependency : artifacts) {
Artifact artifact = dependency.getArtifact();
if (!validateArtifact(artifact)) {
continue;
}
if (SynapseAppDeployerConstants.SYNAPSE_LIBRARY_TYPE.equals(artifact.getType())) {
Deployer deployer = getSynapseLibraryDeployer(axisConfig);
if (deployer != null) {
artifact.setRuntimeObjectName(artifact.getName());
String fileName = artifact.getFiles().get(0).getName();
String artifactPath = artifact.getExtractedPath() + File.separator + fileName;
String artifactDir = getArtifactDirPath(axisConfig, SynapseAppDeployerConstants.SYNAPSE_LIBS);
File artifactInRepo = new File(artifactDir + File.separator + fileName);
if (artifactInRepo.exists()) {
log.warn("Synapse Library " + fileName + " already found in " + artifactInRepo.getAbsolutePath() + ". Ignoring CAPP's artifact");
artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_DEPLOYED);
} else {
try {
deployer.deploy(new DeploymentFileData(new File(artifactPath), deployer));
artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_DEPLOYED);
try {
String artifactName = getArtifactName(artifactPath, axisConfig);
SynapseConfiguration configuration = getSynapseConfiguration(axisConfig);
if (artifactName != null) {
if (configuration.getSynapseImports().get(artifactName) == null) {
String libName = artifactName.substring(artifactName.lastIndexOf("}") + 1);
String libraryPackage = artifactName.substring(1, artifactName.lastIndexOf("}"));
updateStatus(artifactName, libName, libraryPackage, ServiceBusConstants.ENABLED, axisConfig);
}
}
} catch (AxisFault axisFault) {
log.error("Unable to update status for the synapse library : " + axisFault.getMessage());
} catch (NullPointerException nullException) {
log.error("Error while getting qualified name of the synapse library : " + nullException.getMessage());
}
} catch (DeploymentException e) {
artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_FAILED);
log.error("Error while deploying the synapse library : " + e.getMessage());
throw e;
}
}
}
}
}
}
use of org.craftercms.studio.api.v2.deployment.Deployer in project studio by craftercms.
the class SiteServiceImpl method createSiteFromBlueprint.
@Override
@ValidateParams
public void createSiteFromBlueprint(@ValidateStringParam(name = "blueprintId") String blueprintId, @ValidateNoTagsParam(name = "siteName") String siteName, @ValidateStringParam(name = "siteId", maxLength = 50, whitelistedPatterns = "[a-z0-9\\-]*") String siteId, @ValidateStringParam(name = "sandboxBranch") String sandboxBranch, @ValidateNoTagsParam(name = "desc") String desc, Map<String, String> params, boolean createAsOrphan) throws SiteAlreadyExistsException, SiteCreationException, DeployerTargetException, BlueprintNotFoundException, MissingPluginParameterException {
if (exists(siteId)) {
throw new SiteAlreadyExistsException();
}
logger.debug("Get blueprint descriptor for: " + blueprintId);
PluginDescriptor descriptor = sitesServiceInternal.getBlueprintDescriptor(blueprintId);
if (Objects.isNull(descriptor)) {
throw new BlueprintNotFoundException();
}
logger.debug("Validating blueprint parameters");
sitesServiceInternal.validateBlueprintParameters(descriptor, params);
String blueprintLocation = sitesServiceInternal.getBlueprintLocation(blueprintId);
String searchEngine = descriptor.getPlugin().getSearchEngine();
logger.debug("Validate site entitlements");
try {
entitlementValidator.validateEntitlement(EntitlementType.SITE, 1);
} catch (EntitlementException e) {
throw new SiteCreationException("Unable to complete request due to entitlement limits. Please contact " + "your system administrator.", e);
}
logger.info("Starting site creation process for site " + siteName + " from " + blueprintId + " blueprint.");
boolean success = true;
// We must fail site creation if any of the site creations steps fail and rollback
// For example: Create site => create Deployer Target (fail) = fail
// and rollback the whole thing.
// What we need to do for site creation and the order of execution:
// 1) deployer target, 2) git repo, 3) database, 4) kick deployer
String siteUuid = UUID.randomUUID().toString();
// Create the site in the preview deployer
logger.info("Creating deployer targets.");
try {
deployer.createTargets(siteId, searchEngine);
} catch (Exception e) {
success = false;
String msg = "Error while creating site: " + siteName + " ID: " + siteId + " from blueprint: " + blueprintId + ". The required Deployer targets couldn't be created";
logger.error(msg, e);
throw new DeployerTargetException(msg, e);
}
if (success) {
try {
logger.info("Copying site content from blueprint.");
success = createSiteFromBlueprintGit(blueprintLocation, siteName, siteId, sandboxBranch, desc, params);
ZonedDateTime now = ZonedDateTime.now();
logger.debug("Adding site UUID.");
addSiteUuidFile(siteId, siteUuid);
logger.info("Adding site record to database for site " + siteId);
// insert database records
SiteFeed siteFeed = new SiteFeed();
siteFeed.setName(siteName);
siteFeed.setSiteId(siteId);
siteFeed.setSiteUuid(siteUuid);
siteFeed.setDescription(desc);
siteFeed.setPublishingStatus(READY);
siteFeed.setPublishingStatusMessage(studioConfiguration.getProperty(JOB_DEPLOY_CONTENT_TO_ENVIRONMENT_STATUS_MESSAGE_DEFAULT));
siteFeed.setSandboxBranch(sandboxBranch);
siteFeed.setSearchEngine(searchEngine);
siteFeedMapper.createSite(siteFeed);
String localeAddress = studioClusterUtils.getClusterNodeLocalAddress();
ClusterMember cm = clusterDao.getMemberByLocalAddress(localeAddress);
if (Objects.nonNull(cm)) {
SiteFeed s = getSite(siteId);
clusterDao.insertClusterSiteSyncRepo(cm.getId(), s.getId(), null, null, null);
}
logger.info("Upgrading site.");
upgradeManager.upgradeSite(siteId);
// Add default groups
logger.info("Adding default groups");
addDefaultGroupsForNewSite(siteId);
String lastCommitId = contentRepositoryV2.getRepoLastCommitId(siteId);
String creator = securityService.getCurrentUser();
long startGetChangeSetCreatedFilesMark = logger.isDebugEnabled() ? System.currentTimeMillis() : 0;
Map<String, String> createdFiles = contentRepositoryV2.getChangeSetPathsFromDelta(siteId, null, lastCommitId);
if (logger.isDebugEnabled()) {
logger.debug("Get change set created files finished in " + (System.currentTimeMillis() - startGetChangeSetCreatedFilesMark) + " milliseconds");
}
logger.info("Adding audit log");
insertCreateSiteAuditLog(siteId, siteName, createdFiles);
processCreatedFiles(siteId, createdFiles, creator, now, lastCommitId);
contentRepositoryV2.insertGitLog(siteId, lastCommitId, 1, 1);
updateLastCommitId(siteId, lastCommitId);
updateLastVerifiedGitlogCommitId(siteId, lastCommitId);
updateLastSyncedGitlogCommitId(siteId, lastCommitId);
logger.info("Reload site configuration");
reloadSiteConfiguration(siteId);
} catch (Exception e) {
success = false;
logger.error("Error while creating site: " + siteName + " ID: " + siteId + " from blueprint: " + blueprintId + ". Rolling back.", e);
deleteSite(siteId);
throw new SiteCreationException("Error while creating site: " + siteName + " ID: " + siteId + " from blueprint: " + blueprintId + ". Rolling back.");
}
}
if (success) {
logger.info("Syncing all content to preview.");
// Now that everything is created, we can sync the preview deployer with the new content
try {
deploymentService.syncAllContentToPreview(siteId, true);
} catch (ServiceLayerException e) {
logger.error("Error while syncing site: " + siteName + " ID: " + siteId + " to preview. Site was " + "successfully created otherwise. Ignoring.", e);
throw new SiteCreationException("Error while syncing site: " + siteName + " ID: " + siteId + " to preview. Site was successfully created, but it won't be preview-able until the Preview " + "Deployer is reachable.");
}
setSiteState(siteId, STATE_CREATED);
} else {
throw new SiteCreationException("Error while creating site: " + siteName + " ID: " + siteId + ".");
}
logger.info("Finished creating site " + siteId);
}
Aggregations