Search in sources :

Example 1 with DeployInfosResponse

use of org.ystia.yorc.alien4cloud.plugin.rest.Response.DeployInfosResponse 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)

Aggregations

DeploymentStatus (alien4cloud.paas.model.DeploymentStatus)1 InstanceInformation (alien4cloud.paas.model.InstanceInformation)1 Map (java.util.Map)1 AttributeResponse (org.ystia.yorc.alien4cloud.plugin.rest.Response.AttributeResponse)1 DeployInfosResponse (org.ystia.yorc.alien4cloud.plugin.rest.Response.DeployInfosResponse)1 InstanceInfosResponse (org.ystia.yorc.alien4cloud.plugin.rest.Response.InstanceInfosResponse)1 Link (org.ystia.yorc.alien4cloud.plugin.rest.Response.Link)1 NodeInfosResponse (org.ystia.yorc.alien4cloud.plugin.rest.Response.NodeInfosResponse)1