use of alien4cloud.paas.model.InstanceInformation in project yorc-a4c-plugin by ystia.
the class YorcPaaSProvider method updateNodeInfo.
/**
* Update nodeInformation in the YorcRuntimeDeploymentInfo
* This is needed to let a4c know all about the nodes and their instances
* Information is got from Yorc using the REST API
*
* @param ctx PaaSDeploymentContext to be updated
* @return deployment status
*
* @throws
*/
private DeploymentStatus updateNodeInfo(PaaSDeploymentContext ctx) throws Exception {
String paasId = ctx.getDeploymentPaaSId();
String deploymentUrl = "/deployments/" + paasId;
log.debug("updateNodeInfo " + paasId);
// Assumes YorcRuntimeDeploymentInfo already created.
YorcRuntimeDeploymentInfo jrdi = runtimeDeploymentInfos.get(paasId);
if (jrdi == null) {
log.error("No YorcRuntimeDeploymentInfo");
return DeploymentStatus.FAILURE;
}
// Find the deployment info from Yorc
DeployInfosResponse deployRes = restClient.getDeploymentInfosFromYorc(deploymentUrl);
DeploymentStatus ds = getDeploymentStatusFromString(deployRes.getStatus());
jrdi.setStatus(ds);
Map<String, Map<String, InstanceInformation>> nodemap = jrdi.getInstanceInformations();
// Look every node we want to update.
for (Link nodeLink : deployRes.getLinks()) {
if (nodeLink.getRel().equals("node")) {
// Find the node info from Yorc
NodeInfosResponse nodeRes = restClient.getNodesInfosFromYorc(nodeLink.getHref());
String node = nodeRes.getName();
Map<String, InstanceInformation> instanceMap = nodemap.get(node);
if (instanceMap == null) {
// This node was unknown. Create it.
instanceMap = Maps.newHashMap();
nodemap.put(node, instanceMap);
}
// Find information about all the node instances from Yorc
for (Link instanceLink : nodeRes.getLinks()) {
if (instanceLink.getRel().equals("instance")) {
// Find the instance info from Yorc
InstanceInfosResponse instRes = restClient.getInstanceInfosFromYorc(instanceLink.getHref());
String inb = instRes.getId();
InstanceInformation iinfo = instanceMap.get(inb);
if (iinfo == null) {
// This instance was unknown. create it.
iinfo = newInstance(new Integer(inb));
instanceMap.put(inb, iinfo);
}
for (Link link : instRes.getLinks()) {
if (link.getRel().equals("attribute")) {
// Get the attribute from Yorc
AttributeResponse attrRes = restClient.getAttributeFromYorc(link.getHref());
iinfo.getAttributes().put(attrRes.getName(), attrRes.getValue());
log.debug("Attribute: " + attrRes.getName() + "=" + attrRes.getValue());
}
}
// Let a4c know the instance state
updateInstanceState(paasId, node, inb, iinfo, instRes.getStatus());
}
}
}
}
return ds;
}
use of alien4cloud.paas.model.InstanceInformation in project alien4cloud by alien4cloud.
the class ApplicationDeploymentController method getInstanceInformation.
/**
* Get detailed information for every instances of every node of the application on the PaaS.
*
* @param applicationId The id of the application to be deployed.
* @return A {@link RestResponse} that contains detailed informations (See {@link InstanceInformation}) of the application on the PaaS it is deployed.
*/
@ApiOperation(value = "Get detailed informations for every instances of every node of the application on the PaaS.", notes = "Application role required [ APPLICATION_MANAGER | APPLICATION_DEVOPS ] and Application environment role required [ APPLICATION_USER | DEPLOYMENT_MANAGER ]")
@RequestMapping(value = "/{applicationId:.+}/environments/{applicationEnvironmentId}/deployment/informations", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public DeferredResult<RestResponse<Map<String, Map<String, InstanceInformation>>>> getInstanceInformation(@PathVariable String applicationId, @PathVariable String applicationEnvironmentId) {
Application application = applicationService.checkAndGetApplication(applicationId);
ApplicationEnvironment environment = applicationEnvironmentService.getEnvironmentByIdOrDefault(application.getId(), applicationEnvironmentId);
AuthorizationUtil.checkAuthorizationForEnvironment(application, environment, ApplicationEnvironmentRole.values());
Deployment deployment = applicationEnvironmentService.getActiveDeployment(environment.getId());
final DeferredResult<RestResponse<Map<String, Map<String, InstanceInformation>>>> instancesDeferredResult = new DeferredResult<>(5L * 60L * 1000L);
if (deployment == null) {
// if there is no topology associated with the version it could not have been deployed.
instancesDeferredResult.setResult(RestResponseBuilder.<Map<String, Map<String, InstanceInformation>>>builder().build());
} else {
try {
deploymentRuntimeStateService.getInstancesInformation(deployment, new IPaaSCallback<Map<String, Map<String, InstanceInformation>>>() {
@Override
public void onSuccess(Map<String, Map<String, InstanceInformation>> data) {
instancesDeferredResult.setResult(RestResponseBuilder.<Map<String, Map<String, InstanceInformation>>>builder().data(data).build());
}
@Override
public void onFailure(Throwable throwable) {
instancesDeferredResult.setErrorResult(throwable);
}
});
} catch (OrchestratorDisabledException e) {
log.error("Cannot get instance informations as topology plugin cannot be found.", e);
instancesDeferredResult.setResult(RestResponseBuilder.<Map<String, Map<String, InstanceInformation>>>builder().build());
}
}
return instancesDeferredResult;
}
use of alien4cloud.paas.model.InstanceInformation in project alien4cloud by alien4cloud.
the class MockPaaSProvider method switchMaintenanceMode.
@Override
public void switchMaintenanceMode(PaaSDeploymentContext deploymentContext, boolean maintenanceModeOn) {
String deploymentPaaSId = deploymentContext.getDeploymentPaaSId();
MockRuntimeDeploymentInfo runtimeDeploymentInfo = runtimeDeploymentInfos.get(deploymentContext.getDeploymentPaaSId());
Topology topology = runtimeDeploymentInfo.getDeploymentContext().getDeploymentTopology();
Map<String, Map<String, InstanceInformation>> nodes = runtimeDeploymentInfo.getInstanceInformations();
if (nodes == null || nodes.isEmpty()) {
return;
}
for (Entry<String, Map<String, InstanceInformation>> nodeEntry : nodes.entrySet()) {
String nodeTemplateId = nodeEntry.getKey();
Map<String, InstanceInformation> nodeInstances = nodeEntry.getValue();
if (nodeInstances != null && !nodeInstances.isEmpty()) {
NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeTemplateId);
NodeType nodeType = toscaTypeSearchService.getRequiredElementInDependencies(NodeType.class, nodeTemplate.getType(), topology.getDependencies());
if (ToscaTypeUtils.isOfType(nodeType, NormativeComputeConstants.COMPUTE_TYPE)) {
for (Entry<String, InstanceInformation> nodeInstanceEntry : nodeInstances.entrySet()) {
String instanceId = nodeInstanceEntry.getKey();
InstanceInformation instanceInformation = nodeInstanceEntry.getValue();
if (instanceInformation != null) {
switchInstanceMaintenanceMode(deploymentPaaSId, nodeTemplateId, instanceId, instanceInformation, maintenanceModeOn);
}
}
}
}
}
}
use of alien4cloud.paas.model.InstanceInformation in project alien4cloud by alien4cloud.
the class MockPaaSProvider method notifyInstanceStateChanged.
private void notifyInstanceStateChanged(final String deploymentPaaSId, final String nodeId, final String instanceId, final InstanceInformation information, long delay) {
final InstanceInformation cloned = new InstanceInformation();
cloned.setAttributes(information.getAttributes());
cloned.setInstanceStatus(information.getInstanceStatus());
cloned.setRuntimeProperties(information.getRuntimeProperties());
cloned.setState(information.getState());
executorService.schedule(new Runnable() {
@Override
public void run() {
final MockRuntimeDeploymentInfo deploymentInfo = runtimeDeploymentInfos.get(deploymentPaaSId);
Deployment deployment = deploymentInfo.getDeploymentContext().getDeployment();
PaaSInstanceStateMonitorEvent event;
event = new PaaSInstanceStateMonitorEvent();
event.setInstanceId(instanceId.toString());
event.setInstanceState(cloned.getState());
event.setInstanceStatus(cloned.getInstanceStatus());
event.setNodeTemplateId(nodeId);
event.setDate((new Date()).getTime());
event.setDeploymentId(paaSDeploymentIdToAlienDeploymentIdMap.get(deploymentPaaSId));
event.setRuntimeProperties(cloned.getRuntimeProperties());
event.setAttributes(cloned.getAttributes());
toBeDeliveredEvents.add(event);
if (deployment.getSourceName().equals(BLOCKSTORAGE_APPLICATION) && cloned.getState().equalsIgnoreCase("created")) {
PaaSInstancePersistentResourceMonitorEvent prme = new PaaSInstancePersistentResourceMonitorEvent(nodeId, instanceId.toString(), MapUtil.newHashMap(new String[] { NormativeBlockStorageConstants.VOLUME_ID }, new Object[] { UUID.randomUUID().toString() }));
prme.setDeploymentId(deployment.getId());
toBeDeliveredEvents.add(prme);
}
PaaSMessageMonitorEvent messageMonitorEvent = new PaaSMessageMonitorEvent();
messageMonitorEvent.setDate((new Date()).getTime());
messageMonitorEvent.setDeploymentId(paaSDeploymentIdToAlienDeploymentIdMap.get(deploymentPaaSId));
messageMonitorEvent.setMessage("APPLICATIONS.RUNTIME.EVENTS.MESSAGE_EVENT.INSTANCE_STATE_CHANGED");
toBeDeliveredEvents.add(messageMonitorEvent);
}
}, delay, TimeUnit.SECONDS);
}
use of alien4cloud.paas.model.InstanceInformation in project alien4cloud by alien4cloud.
the class MockPaaSProvider method switchInstanceMaintenanceMode.
@Override
public void switchInstanceMaintenanceMode(PaaSDeploymentContext deploymentContext, String nodeTemplateId, String instanceId, boolean maintenanceModeOn) {
log.info(String.format("switchInstanceMaintenanceMode order received for node <%s>, instance <%s>, mode <%s>", nodeTemplateId, instanceId, maintenanceModeOn));
MockRuntimeDeploymentInfo runtimeDeploymentInfo = runtimeDeploymentInfos.get(deploymentContext.getDeploymentPaaSId());
if (runtimeDeploymentInfo == null) {
return;
}
final Map<String, Map<String, InstanceInformation>> existingInformations = runtimeDeploymentInfo.getInstanceInformations();
if (existingInformations != null && existingInformations.containsKey(nodeTemplateId) && existingInformations.get(nodeTemplateId).containsKey(instanceId)) {
InstanceInformation instanceInformation = existingInformations.get(nodeTemplateId).get(instanceId);
switchInstanceMaintenanceMode(deploymentContext.getDeploymentPaaSId(), nodeTemplateId, instanceId, instanceInformation, maintenanceModeOn);
}
}
Aggregations