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());
}
}
}
}
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;
}
Aggregations