Search in sources :

Example 1 with InstanceInformation

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;
}
Also used : DeployInfosResponse(org.ystia.yorc.alien4cloud.plugin.rest.Response.DeployInfosResponse) InstanceInformation(alien4cloud.paas.model.InstanceInformation) NodeInfosResponse(org.ystia.yorc.alien4cloud.plugin.rest.Response.NodeInfosResponse) AttributeResponse(org.ystia.yorc.alien4cloud.plugin.rest.Response.AttributeResponse) InstanceInfosResponse(org.ystia.yorc.alien4cloud.plugin.rest.Response.InstanceInfosResponse) Map(java.util.Map) DeploymentStatus(alien4cloud.paas.model.DeploymentStatus) Link(org.ystia.yorc.alien4cloud.plugin.rest.Response.Link)

Example 2 with InstanceInformation

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;
}
Also used : RestResponse(alien4cloud.rest.model.RestResponse) Deployment(alien4cloud.model.deployment.Deployment) InstanceInformation(alien4cloud.paas.model.InstanceInformation) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) OrchestratorDisabledException(alien4cloud.paas.exception.OrchestratorDisabledException) Application(alien4cloud.model.application.Application) Map(java.util.Map) DeferredResult(org.springframework.web.context.request.async.DeferredResult) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with InstanceInformation

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);
                    }
                }
            }
        }
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) InstanceInformation(alien4cloud.paas.model.InstanceInformation) Topology(org.alien4cloud.tosca.model.templates.Topology) Map(java.util.Map)

Example 4 with InstanceInformation

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);
}
Also used : PaaSInstanceStateMonitorEvent(alien4cloud.paas.model.PaaSInstanceStateMonitorEvent) PaaSInstancePersistentResourceMonitorEvent(alien4cloud.paas.model.PaaSInstancePersistentResourceMonitorEvent) InstanceInformation(alien4cloud.paas.model.InstanceInformation) Deployment(alien4cloud.model.deployment.Deployment) PaaSMessageMonitorEvent(alien4cloud.paas.model.PaaSMessageMonitorEvent) Date(java.util.Date)

Example 5 with InstanceInformation

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);
    }
}
Also used : InstanceInformation(alien4cloud.paas.model.InstanceInformation) Map(java.util.Map)

Aggregations

InstanceInformation (alien4cloud.paas.model.InstanceInformation)11 Map (java.util.Map)8 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)4 Topology (org.alien4cloud.tosca.model.templates.Topology)3 Deployment (alien4cloud.model.deployment.Deployment)2 Application (alien4cloud.model.application.Application)1 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)1 MaintenanceModeException (alien4cloud.paas.exception.MaintenanceModeException)1 OrchestratorDisabledException (alien4cloud.paas.exception.OrchestratorDisabledException)1 DeploymentStatus (alien4cloud.paas.model.DeploymentStatus)1 PaaSInstancePersistentResourceMonitorEvent (alien4cloud.paas.model.PaaSInstancePersistentResourceMonitorEvent)1 PaaSInstanceStateMonitorEvent (alien4cloud.paas.model.PaaSInstanceStateMonitorEvent)1 PaaSMessageMonitorEvent (alien4cloud.paas.model.PaaSMessageMonitorEvent)1 PaaSNodeTemplate (alien4cloud.paas.model.PaaSNodeTemplate)1 RestResponse (alien4cloud.rest.model.RestResponse)1 ApiOperation (io.swagger.annotations.ApiOperation)1 Date (java.util.Date)1 Hashtable (java.util.Hashtable)1 Set (java.util.Set)1 ManagedServiceUpdatedEvent (org.alien4cloud.alm.events.ManagedServiceUpdatedEvent)1