addToPayload(payload, "MEMBER_ID", memberID);
addToPayload(payload, "LB_CLUSTER_ID", memberContext.getLbClusterId());
addToPayload(payload, "NETWORK_PARTITION_ID", memberContext.getNetworkPartitionId());
addToPayload(payload, "PARTITION_ID", partitionId);
Iaas iaas = iaasProvider.getIaas();
if(ctxt.isVolumeRequired()){
addToPayload(payload, "PERSISTENCE_MAPPING", getPersistencePayload(cartridge, iaas).toString());
}
if (log.isDebugEnabled()) {
log.debug("Payload: " + payload.toString());
}
// reloading the payload with memberID
iaasProvider.setPayload(payload.toString().getBytes());
if (iaas == null) {
if(log.isDebugEnabled()) {
log.debug("Iaas is null of Iaas Provider: "+type+". Trying to build IaaS...");
}
try {
iaas = CloudControllerUtil.getIaas(iaasProvider);
} catch (InvalidIaasProviderException e) {
String msg ="Instance start up failed. "+memberContext.toString()+
"Unable to build Iaas of this IaasProvider [Provider] : " + type+". Cause: "+e.getMessage();
log.error(msg, e);
throw new InvalidIaasProviderException(msg, e);
}
}
iaas.setDynamicPayload();
// get the pre built ComputeService from provider or region or zone or host
computeService = iaasProvider.getComputeService();
template = iaasProvider.getTemplate();
if (template == null) {
String msg =
"Failed to start an instance. " +
memberContext.toString() +
". Reason : Jclouds Template is null for iaas provider [type]: "+iaasProvider.getType();
log.error(msg);
throw new InvalidIaasProviderException(msg);
}
// generate the group id from domain name and sub domain
// name.
// Should have lower-case ASCII letters, numbers, or dashes.
// Should have a length between 3-15
String str = clusterId.length() > 10 ? clusterId.substring(0, 10) : clusterId.substring(0, clusterId.length());
String group = str.replaceAll("[^a-z0-9-]", "");
if(ctxt.isVolumeRequired()) {
if (ctxt.getVolumes() != null) {
for (Volume volume : ctxt.getVolumes()) {
if (volume.getId() == null) {
// create a new volume
createVolumeAndSetInClusterContext(volume, iaasProvider);
}
}
}
}
NodeMetadata node;
// create and start a node
Set<? extends NodeMetadata> nodes =
computeService.createNodesInGroup(group, 1,
template);
node = nodes.iterator().next();
//Start allocating ip as a new job
ThreadExecutor exec = ThreadExecutor.getInstance();
exec.execute(new IpAllocator(memberContext, iaasProvider, cartridgeType, node));
// node id
String nodeId = node.getId();
if (nodeId == null) {
String msg = "Node id of the starting instance is null.\n" + memberContext.toString();
log.fatal(msg);
throw new IllegalStateException(msg);
}
memberContext.setNodeId(nodeId);
if(log.isDebugEnabled()) {
log.debug("Node id was set. "+memberContext.toString());
}
// attach volumes
if (ctxt.isVolumeRequired()) {
// remove region prefix
String instanceId = nodeId.indexOf('/') != -1 ? nodeId
.substring(nodeId.indexOf('/') + 1, nodeId.length())
: nodeId;
memberContext.setInstanceId(instanceId);
if (ctxt.getVolumes() != null) {
for (Volume volume : ctxt.getVolumes()) {
try {
iaas.attachVolume(instanceId, volume.getId(),
volume.getDevice());
} catch (Exception e) {
// continue without throwing an exception, since
// there is an instance already running
log.error("Attaching Volume to Instance [ "