* {@link QNodeHandler}. Returns a {@link QueryStatus} with the status of the request.
*
* @throws InterruptedException
*/
public DeployInfo deploy(List<DeployRequest> deployRequests) throws InterruptedException {
DeployInfo deployInfo = new DeployInfo();
// A new unique version number is generated.
long version = context.getCoordinationStructures().uniqueVersionId();
deployInfo.setVersion(version);
List<String> tablespaces = new ArrayList<String>();
List<String> dataURIs = new ArrayList<String>();
for(DeployRequest request : deployRequests) {
tablespaces.add(request.getTablespace());
dataURIs.add(request.getData_uri());
}
deployInfo.setTablespacesDeployed(tablespaces);
deployInfo.setDataURIs(dataURIs);
Date startTime = new Date();
deployInfo.setStartedAt(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(startTime));
context.getCoordinationStructures().logDeployMessage(version,
"Deploy [" + version + "] for tablespaces " + tablespaces + " started.");
context.getCoordinationStructures().getDeploymentsStatusPanel().put(version, DeployStatus.ONGOING);
// Generate the list of actions per DNode
Map<String, List<DeployAction>> actionsPerDNode = generateDeployActionsPerDNode(deployRequests,
version);
// Starting the countdown latch.
ICountDownLatch countDownLatchForDeploy = context.getCoordinationStructures()
.getCountDownLatchForDeploy(version);
Set<String> dnodesInvolved = actionsPerDNode.keySet();
countDownLatchForDeploy.trySetCount(dnodesInvolved.size());
// Sending deploy signals to each DNode
for(Map.Entry<String, List<DeployAction>> actionPerDNode : actionsPerDNode.entrySet()) {
DNodeService.Client client = null;
boolean renew = false;
try {
try {
client = context.getDNodeClientFromPool(actionPerDNode.getKey());
} catch(TTransportException e) {
renew = true;
throw e;
}
client.deploy(actionPerDNode.getValue(), version);
} catch(Exception e) {
String errorMsg = "Error sending deploy actions to DNode [" + actionPerDNode.getKey() + "]";
log.error(errorMsg, e);
abortDeploy(new ArrayList<String>(actionsPerDNode.keySet()), errorMsg, version);
deployInfo.setError("Error connecting to DNode " + actionPerDNode.getKey());
context.getCoordinationStructures().getDeployInfoPanel().put(version, deployInfo);
return deployInfo;
} finally {
context.returnDNodeClientToPool(actionPerDNode.getKey(), client, renew);
}