use of alien4cloud.model.deployment.DeploymentTopology in project yorc-a4c-plugin by ystia.
the class ShowTopology method topologyInLog.
/**
* Log topology infos for debugging
* @param ctx
*/
public static void topologyInLog(PaaSTopologyDeploymentContext ctx) {
String paasId = ctx.getDeploymentPaaSId();
PaaSTopology ptopo = ctx.getPaaSTopology();
DeploymentTopology dtopo = ctx.getDeploymentTopology();
// Deployment Workflows
Map<String, Workflow> workflows = dtopo.getWorkflows();
for (String wfname : workflows.keySet()) {
log.debug("***** Workflow " + wfname);
Workflow wf = workflows.get(wfname);
log.debug("name: " + wf.getName());
log.debug("host: " + wf.getHosts().toString());
log.debug("steps: " + wf.getSteps().keySet().toString());
}
// Deployment Groups
Map<String, NodeGroup> groups = dtopo.getGroups();
if (groups != null) {
for (String grname : groups.keySet()) {
NodeGroup group = groups.get(grname);
log.debug("***** Group " + grname);
log.debug("name: " + group.getName());
log.debug("members: " + group.getMembers().toString());
}
}
// PaaS Compute Nodes
for (PaaSNodeTemplate node : ptopo.getAllNodes().values()) {
printNode(node);
}
}
use of alien4cloud.model.deployment.DeploymentTopology in project yorc-a4c-plugin by ystia.
the class DeployTask method buildZip.
/**
* Create the zip for yorc, with a modified yaml and all needed archives.
* Assumes a file original.yml exists in the current directory
* @param ctx all needed information about the deployment
* @throws IOException
*/
private void buildZip(PaaSTopologyDeploymentContext ctx) throws IOException {
// Check location
int location = LOC_OPENSTACK;
Location loc = ctx.getLocations().get("_A4C_ALL");
Set<CSARDependency> locdeps = loc.getDependencies();
for (CSARDependency dep : locdeps) {
if (dep.getName().contains("kubernetes")) {
location = LOC_KUBERNETES;
break;
}
if (dep.getName().contains("slurm")) {
location = LOC_SLURM;
break;
}
if (dep.getName().contains("aws")) {
location = LOC_AWS;
break;
}
}
// Final zip file will be named topology.zip
final File zip = new File("topology.zip");
final OutputStream out = new FileOutputStream(zip);
final ZipOutputStream zout = new ZipOutputStream(out);
final Closeable res = zout;
final int finalLocation = location;
this.ctx.getDeploymentTopology().getDependencies().forEach(d -> {
if (!"tosca-normative-types".equals(d.getName())) {
Csar csar = csarRepoSearchService.getArchive(d.getName(), d.getVersion());
if (CSARSource.ORCHESTRATOR != CSARSource.valueOf(csar.getImportSource())) {
try {
csar2zip(zout, csar, finalLocation);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
});
// Copy overwritten artifacts for each node
PaaSTopology ptopo = ctx.getPaaSTopology();
for (PaaSNodeTemplate node : ptopo.getAllNodes().values()) {
copyArtifacts(node, zout);
}
String topoFileName = "topology.yml";
// Copy modified topology
createZipEntries(topoFileName, zout);
// Get the yaml of the application as built by from a4c
DeploymentTopology dtopo = ctx.getDeploymentTopology();
Csar myCsar = new Csar(ctx.getDeploymentPaaSId(), dtopo.getArchiveVersion());
myCsar.setToscaDefinitionsVersion(ToscaParser.LATEST_DSL);
String yaml = orchestrator.getToscaTopologyExporter().getYaml(myCsar, dtopo, true);
zout.write(yaml.getBytes(Charset.forName("UTF-8")));
zout.closeEntry();
res.close();
}
use of alien4cloud.model.deployment.DeploymentTopology in project yorc-a4c-plugin by ystia.
the class DeployTask method run.
/**
* Execute the Deployment
*/
public void run() {
Throwable error = null;
// Keep Ids in a Map
String paasId = ctx.getDeploymentPaaSId();
String alienId = ctx.getDeploymentId();
String deploymentUrl = "/deployments/" + paasId;
log.debug("Deploying " + paasId + "with id : " + alienId);
orchestrator.putDeploymentId(paasId, alienId);
// Init Deployment Info from topology
DeploymentTopology dtopo = ctx.getDeploymentTopology();
Map<String, Map<String, InstanceInformation>> curinfo = setupInstanceInformations(dtopo);
YorcRuntimeDeploymentInfo jrdi = new YorcRuntimeDeploymentInfo(ctx, DeploymentStatus.INIT_DEPLOYMENT, curinfo, deploymentUrl);
orchestrator.putDeploymentInfo(paasId, jrdi);
orchestrator.doChangeStatus(paasId, DeploymentStatus.INIT_DEPLOYMENT);
// Show Topoloy for debug
ShowTopology.topologyInLog(ctx);
MappingTosca.quoteProperties(ctx);
// This operation must be synchronized, because it uses the same files topology.yml and topology.zip
String taskUrl;
synchronized (this) {
// Create the yml of our topology and build our zip topology
try {
buildZip(ctx);
} catch (Throwable e) {
orchestrator.doChangeStatus(paasId, DeploymentStatus.FAILURE);
callback.onFailure(e);
return;
}
// put topology zip to Yorc
log.info("PUT Topology to Yorc");
try {
taskUrl = restClient.sendTopologyToYorc(paasId);
} catch (Exception e) {
orchestrator.sendMessage(paasId, "Deployment not accepted by Yorc: " + e.getMessage());
orchestrator.doChangeStatus(paasId, DeploymentStatus.FAILURE);
callback.onFailure(e);
return;
}
}
String taskId = taskUrl.substring(taskUrl.lastIndexOf("/") + 1);
jrdi.setDeployTaskId(taskId);
orchestrator.sendMessage(paasId, "Deployment sent to Yorc. TaskId=" + taskId);
// wait for Yorc deployment completion
boolean done = false;
long timeout = System.currentTimeMillis() + YORC_DEPLOY_TIMEOUT;
Event evt;
while (!done && error == null) {
synchronized (jrdi) {
// Check deployment timeout
long timetowait = timeout - System.currentTimeMillis();
if (timetowait <= 0) {
log.warn("Deployment Timeout occured");
error = new Throwable("Deployment timeout");
orchestrator.doChangeStatus(paasId, DeploymentStatus.FAILURE);
break;
}
// Wait Deployment Events from Yorc
log.debug(paasId + ": Waiting for deployment events.");
try {
jrdi.wait(timetowait);
} catch (InterruptedException e) {
log.warn("Interrupted while waiting for deployment");
}
// Check if we received a Deployment Event and process it
evt = jrdi.getLastEvent();
if (evt != null && evt.getType().equals(EventListenerTask.EVT_DEPLOYMENT)) {
jrdi.setLastEvent(null);
switch(evt.getStatus()) {
case "deployment_failed":
log.warn("Deployment failed: " + paasId);
orchestrator.doChangeStatus(paasId, DeploymentStatus.FAILURE);
error = new Exception("Deployment failed");
break;
case "deployed":
log.debug("Deployment success: " + paasId);
orchestrator.doChangeStatus(paasId, DeploymentStatus.DEPLOYED);
done = true;
break;
case "deployment_in_progress":
orchestrator.doChangeStatus(paasId, DeploymentStatus.DEPLOYMENT_IN_PROGRESS);
break;
default:
orchestrator.sendMessage(paasId, "Deployment status = " + evt.getStatus());
break;
}
continue;
}
}
// We were awaken for some bad reason or a timeout
// Check Deployment Status to decide what to do now.
String status;
try {
status = restClient.getStatusFromYorc(deploymentUrl);
} catch (YorcRestException jre) {
if (jre.getHttpStatusCode() == 404) {
// assumes it is undeployed
status = "UNDEPLOYED";
} else {
log.error("yorc deployment returned an exception: " + jre.getMessage());
error = jre;
break;
}
} catch (Exception e) {
log.error("yorc deployment returned an exception: " + e.getMessage());
error = e;
break;
}
switch(status) {
case "UNDEPLOYED":
orchestrator.changeStatus(paasId, DeploymentStatus.UNDEPLOYED);
error = new Throwable("Deployment has been undeployed");
break;
case "DEPLOYED":
// Deployment is OK.
orchestrator.changeStatus(paasId, DeploymentStatus.DEPLOYED);
done = true;
break;
default:
log.debug("Deployment Status is currently " + status);
break;
}
}
synchronized (jrdi) {
// Task is ended: Must remove the taskId and notify a possible undeploy waiting for it.
jrdi.setDeployTaskId(null);
jrdi.notify();
}
// Return result to a4c
if (error == null) {
callback.onSuccess(null);
} else {
callback.onFailure(error);
}
}
use of alien4cloud.model.deployment.DeploymentTopology in project alien4cloud by alien4cloud.
the class DeploymentServiceTest method isArchiveDeployedTest.
@Test
public void isArchiveDeployedTest() {
DeploymentTopology deploymentTopology = new DeploymentTopology();
deploymentTopology.setId("id");
deploymentTopology.setDeployed(false);
deploymentTopology.setDependencies(Sets.newHashSet(new CSARDependency("toto", "2.0.0")));
alienMonitorDao.save(deploymentTopology);
deploymentTopology.setId("id2");
deploymentTopology.setDeployed(true);
deploymentTopology.setDependencies(Sets.newHashSet(new CSARDependency("tata", "1.0.0")));
alienMonitorDao.save(deploymentTopology);
deploymentTopology.setId("id3");
deploymentTopology.setDeployed(true);
deploymentTopology.setDependencies(Sets.newHashSet(new CSARDependency("toto", "1.0.0")));
alienMonitorDao.save(deploymentTopology);
Assert.assertFalse(deploymentService.isArchiveDeployed("toto", "2.0.0"));
deploymentTopology.setId("id");
deploymentTopology.setDeployed(true);
deploymentTopology.setDependencies(Sets.newHashSet(new CSARDependency("toto", "2.0.0")));
alienMonitorDao.save(deploymentTopology);
Assert.assertTrue(deploymentService.isArchiveDeployed("toto", "2.0.0"));
}
use of alien4cloud.model.deployment.DeploymentTopology in project alien4cloud by alien4cloud.
the class ApplicationDeploymentController method getRuntimeTopology.
/**
* Get runtime topology of an application on a specific environment or the current deployment topology if no deployment is active.
* This method is necessary for example to compute output properties / attributes on the client side.
*
* @param applicationId application id for which to get the topology
* @param applicationEnvironmentId application environment for which to get the topology
* @return {@link RestResponse}<{@link TopologyDTO}> containing the requested runtime {@link Topology} and the
* {@link NodeType} related to its {@link NodeTemplate}s
*/
@ApiOperation(value = "Get last runtime (deployed) topology of an application or else get the current deployment topology for the environment.")
@RequestMapping(value = "/{applicationId:.+?}/environments/{applicationEnvironmentId:.+?}/runtime-topology", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<TopologyDTO> getRuntimeTopology(@ApiParam(value = "Id of the application for which to get deployed topology.", required = true) @PathVariable String applicationId, @ApiParam(value = "Id of the environment for which to get deployed topology.", required = true) @PathVariable String applicationEnvironmentId) {
ApplicationEnvironment environment = applicationEnvironmentService.getEnvironmentByIdOrDefault(applicationId, applicationEnvironmentId);
if (!environment.getApplicationId().equals(applicationId)) {
throw new NotFoundException("Unable to find environment with id <" + applicationEnvironmentId + "> for application <" + applicationId + ">");
}
AuthorizationUtil.checkAuthorizationForEnvironment(applicationService.getOrFail(applicationId), environment, ApplicationEnvironmentRole.APPLICATION_USER);
Deployment deployment = deploymentService.getActiveDeployment(environment.getId());
DeploymentTopology deploymentTopology = null;
if (deployment != null) {
deploymentTopology = deploymentRuntimeStateService.getRuntimeTopology(deployment.getId());
}
return RestResponseBuilder.<TopologyDTO>builder().data(topologyDTOBuilder.initTopologyDTO(deploymentTopology, new TopologyDTO())).build();
}
Aggregations