JsonNode actualObj = null;
try {
actualObj = MAPPER.readValue(keyJson, JsonNode.class);
} catch (IOException e) {
LOGGER.info("Can not read Json node: ", e);
throw new InternalServerException("Can not read Json node: ", e);
}
String storageAccountKey = actualObj.get("StorageService").get("StorageServiceKeys").get("Primary").asText();
AzureClientUtil.createBlobContainer(storageAccountKey, targetBlobContainerUri);
AzureClientUtil.copyOsImage(storageAccountKey, baseImageUri, targetImageUri);
String copyStatus = PENDING;
while (PENDING.equals(copyStatus)) {
Map<String, String> copyStatusFromServer = (Map<String, String>) AzureClientUtil.getCopyOsImageProgress(storageAccountKey, targetImageUri);
copyStatus = copyStatusFromServer.get("status");
Long copied = Long.valueOf(copyStatusFromServer.get("copiedBytes"));
Long total = Long.valueOf(copyStatusFromServer.get("totalBytes"));
double copyPercentage = (long) ((float) copied / total * ONE_HUNDRED);
LOGGER.info(String.format("copy progress=%s / %s percentage: %s%%.",
copyStatusFromServer.get("copiedBytes"),
copyStatusFromServer.get("totalBytes"),
copyPercentage));
websocketService.sendToTopicUser(stack.getOwner(), WebsocketEndPoint.COPY_IMAGE,
new StatusMessage(stack.getId(), stack.getName(), PENDING, String.format("The copy status is: %s%%.", copyPercentage)));
retryingStackUpdater.updateStackStatusReason(stack.getId(), String.format("The copy status is: %s%%.", copyPercentage));
try {
Thread.sleep(MILLIS);
} catch (InterruptedException e) {
LOGGER.info("Interrupted exception occured during sleep.", e);
Thread.currentThread().interrupt();
}
}
if (!SUCCESS.equals(copyStatus)) {
throw new InternalServerException("Copy OS image failed with status: " + copyStatus);
}
params = new HashMap<>();
params.put(AzureStackUtil.NAME, azureStackUtil.getOsImageName(credential));
params.put(OS, "Linux");
params.put(MEDIALINK, targetImageUri);