Search in sources :

Example 1 with AttributeResponse

use of org.ystia.yorc.alien4cloud.plugin.rest.Response.AttributeResponse in project yorc-a4c-plugin by ystia.

the class YorcPaaSProvider method updateInstanceAttributes.

/**
 * Ask Yorc the values of all attributes for this node/instance
 * This method should never throw Exception.
 * @param paasId
 * @param iinfo
 * @param node
 * @param instance
 */
public void updateInstanceAttributes(String paasId, InstanceInformation iinfo, String node, String instance) {
    String url = "/deployments/" + paasId + "/nodes/" + node + "/instances/" + instance;
    InstanceInfosResponse instInfoRes;
    try {
        instInfoRes = restClient.getInstanceInfosFromYorc(url);
    } catch (Exception e) {
        log.error("Could not get instance info: ", e);
        sendMessage(paasId, "Could not get instance info: " + e.getMessage());
        return;
    }
    for (Link link : instInfoRes.getLinks()) {
        if (link.getRel().equals("attribute")) {
            try {
                // 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());
            } catch (Exception e) {
                log.error("Error getting instance attribute " + link.getHref());
                sendMessage(paasId, "Error getting instance attribute " + link.getHref());
            }
        }
    }
}
Also used : AttributeResponse(org.ystia.yorc.alien4cloud.plugin.rest.Response.AttributeResponse) InstanceInfosResponse(org.ystia.yorc.alien4cloud.plugin.rest.Response.InstanceInfosResponse) MaintenanceModeException(alien4cloud.paas.exception.MaintenanceModeException) OperationExecutionException(alien4cloud.paas.exception.OperationExecutionException) YorcRestException(org.ystia.yorc.alien4cloud.plugin.rest.YorcRestException) PluginConfigurationException(alien4cloud.paas.exception.PluginConfigurationException) Link(org.ystia.yorc.alien4cloud.plugin.rest.Response.Link)

Example 2 with AttributeResponse

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

AttributeResponse (org.ystia.yorc.alien4cloud.plugin.rest.Response.AttributeResponse)2 InstanceInfosResponse (org.ystia.yorc.alien4cloud.plugin.rest.Response.InstanceInfosResponse)2 Link (org.ystia.yorc.alien4cloud.plugin.rest.Response.Link)2 MaintenanceModeException (alien4cloud.paas.exception.MaintenanceModeException)1 OperationExecutionException (alien4cloud.paas.exception.OperationExecutionException)1 PluginConfigurationException (alien4cloud.paas.exception.PluginConfigurationException)1 DeploymentStatus (alien4cloud.paas.model.DeploymentStatus)1 InstanceInformation (alien4cloud.paas.model.InstanceInformation)1 Map (java.util.Map)1 DeployInfosResponse (org.ystia.yorc.alien4cloud.plugin.rest.Response.DeployInfosResponse)1 NodeInfosResponse (org.ystia.yorc.alien4cloud.plugin.rest.Response.NodeInfosResponse)1 YorcRestException (org.ystia.yorc.alien4cloud.plugin.rest.YorcRestException)1