Package com.sequenceiq.cloud.azure.client

Examples of com.sequenceiq.cloud.azure.client.AzureClient


        MDCBuilder.buildMdcContext(stack);
        Credential credential = stack.getCredential();
        String emailAsFolder = azureStackUtil.emailAsFolder(stack.getOwner());

        String filePath = AzureCertificateService.getUserJksFileName(credential, emailAsFolder);
        AzureClient azureClient = azureStackUtil.createAzureClient(credential, filePath);
        if (!azureClient.isImageAvailable(azureStackUtil.getOsImageName(credential))) {
            String affinityGroupName = ((AzureCredential) credential).getCommonName();
            createAffinityGroup(stack, azureClient, affinityGroupName);
            String storageName = String.format("%s%s", VM_COMMON_NAME, stack.getId());
            createStorage(stack, azureClient, affinityGroupName);
            String targetBlobContainerUri = "http://" + affinityGroupName + ".blob.core.windows.net/vm-images";
            String targetImageUri = targetBlobContainerUri + '/' + storageName + ".vhd";
            Map<String, String> params = new HashMap<>();
            params.put(AzureStackUtil.NAME, affinityGroupName);
            String keyJson = (String) azureClient.getStorageAccountKeys(params);

            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);
            azureClient.addOsImage(params);
        }
        LOGGER.info("Publishing {} event [StackId: '{}']", ReactorConfig.PROVISION_SETUP_COMPLETE_EVENT, stack.getId());
        reactor.notify(ReactorConfig.PROVISION_SETUP_COMPLETE_EVENT,
                Event.wrap(new ProvisionSetupComplete(getCloudPlatform(), stack.getId())
                                .withSetupProperty(CREDENTIAL, stack.getCredential())
View Full Code Here


    private static final Logger LOGGER = LoggerFactory.getLogger(AzureInstanceStatusCheckerTask.class);

    @Override
    public boolean checkStatus(AzureInstances instances) {
        MDCBuilder.buildMdcContext(instances.getStack());
        AzureClient azureClient = instances.getAzureClient();
        for (String instance : instances.getInstances()) {
            Map<String, String> vmContext = AzureStackUtil.createVMContext(instance);
            String status = instances.getStatus();
            if (!status.equals(azureClient.getVirtualMachineState(vmContext))) {
                LOGGER.info("Azure instance is not in {} status on stack.", status);
                return false;
            }
        }
        return true;
View Full Code Here

                + String.valueOf(new Date().getTime());
        Map<String, String> props = new HashMap<>();
        props.put(NAME, vmName);
        props.put(DESCRIPTION, azureTemplate.getDescription());
        props.put(AFFINITYGROUP, po.getCommonName());
        AzureClient azureClient = po.getNewAzureClient(azureCredential);
        HttpResponseDecorator cloudServiceResponse = (HttpResponseDecorator) azureClient.createCloudService(props);
        String requestId = (String) azureClient.getRequestId(cloudServiceResponse);
        waitUntilComplete(azureClient, requestId);
        return Arrays.asList(new Resource(ResourceType.AZURE_CLOUD_SERVICE, vmName, stack));
    }
View Full Code Here

                new AzureCloudServiceDeleteTaskContext(aDCO.getCommonName(), resource.getResourceName(),
                        stack, aDCO.getNewAzureClient(credential));
        azureCloudServiceRemoveReadyPollerObjectPollingService
                .pollWithTimeout(azureCloudServiceDeleteTask, azureCloudServiceDeleteTaskContext, POLLING_INTERVAL, MAX_POLLING_ATTEMPTS);

        AzureClient azureClient = aDCO.getNewAzureClient(credential);
        JsonNode actualObj = MAPPER.readValue((String) azureClient.getDisks(), JsonNode.class);
        List<String> disks = (List<String>) actualObj.get("Disks").findValues("Disk").get(0).findValuesAsText("Name");
        for (String jsonNode : disks) {
            if (jsonNode.startsWith(String.format("%s-%s-0", resource.getResourceName(), resource.getResourceName()))) {
                AzureDiskRemoveDeleteTaskContext azureDiskRemoveReadyPollerObject = new AzureDiskRemoveDeleteTaskContext(aDCO.getCommonName(), jsonNode,
                        stack, aDCO.getNewAzureClient(credential));
View Full Code Here

        AzureCredential credential = (AzureCredential) stack.getCredential();
        Map<String, String> props = new HashMap<>();
        props.put(SERVICENAME, resource.getResourceName());
        props.put(NAME, resource.getResourceName());
        try {
            AzureClient azureClient = aDCO.getNewAzureClient(credential);
            Object virtualMachine = azureClient.getVirtualMachine(props);
            return Optional.fromNullable(virtualMachine.toString());
        } catch (Exception ex) {
            return Optional.fromNullable(String.format("{\"Deployment\": {%s}}", ERROR));
        }
    }
View Full Code Here

        props.put(VIRTUAL_NETWORK_IP_ADDRESS, internalIp);
        props.put(CUSTOMDATA, new String(Base64.encodeBase64(po.getUserData().getBytes())));
        props.put(VIRTUALNETWORKNAME, po.filterResourcesByType(ResourceType.AZURE_NETWORK).get(0).getResourceName());
        props.put(PORTS, ports);
        props.put(VMTYPE, AzureVmType.valueOf(azureTemplate.getVmType()).vmType().replaceAll(" ", ""));
        AzureClient azureClient = po.getNewAzureClient(azureCredential);
        HttpResponseDecorator virtualMachineResponse = (HttpResponseDecorator) azureClient.createVirtualMachine(props);
        String requestId = (String) azureClient.getRequestId(virtualMachineResponse);
        waitUntilComplete(azureClient, requestId);
        return Arrays.asList(new Resource(resourceType(), vmName, stack));
    }
View Full Code Here

        AzureCredential credential = (AzureCredential) stack.getCredential();
        try {
            Map<String, String> props = new HashMap<>();
            props.put(SERVICENAME, resource.getResourceName());
            props.put(NAME, resource.getResourceName());
            AzureClient azureClient = aDCO.getNewAzureClient(credential);
            HttpResponseDecorator deleteVirtualMachineResult = (HttpResponseDecorator) azureClient.deleteVirtualMachine(props);
            String requestId = (String) azureClient.getRequestId(deleteVirtualMachineResult);
            waitUntilComplete(azureClient, requestId);
        } catch (HttpResponseException ex) {
            httpResponseExceptionHandler(ex, resource.getResourceName(), stack.getOwner(), stack);
        } catch (Exception ex) {
            throw new InternalServerException(ex.getMessage());
View Full Code Here

    @Override
    public Optional<String> describe(Resource resource, AzureDescribeContextObject aDCO) throws Exception {
        Stack stack = stackRepository.findById(aDCO.getStackId());
        AzureCredential credential = (AzureCredential) stack.getCredential();
        try {
            AzureClient azureClient = aDCO.getNewAzureClient(credential);
            Object cloudService = azureClient.getCloudService(resource.getResourceName());
            return Optional.fromNullable(cloudService.toString());
        } catch (Exception ex) {
            return Optional.fromNullable(String.format("{\"HostedService\": {%s}}", ERROR));
        }
    }
View Full Code Here

        return emailAsFolder;
    }

    public synchronized AzureClient getNewAzureClient(AzureCredential credential) {
        File file = new File(AzureCertificateService.getUserJksFileName(credential, emailAsFolder));
        return new AzureClient(credential.getSubscriptionId(), file.getAbsolutePath(), credential.getJks());
    }
View Full Code Here

        AzureCredential credential = (AzureCredential) stack.getCredential();
        Map<String, String> props;
        try {
            props = new HashMap<>();
            props.put(NAME, resource.getResourceName());
            AzureClient azureClient = aDCO.getNewAzureClient(credential);
            HttpResponseDecorator deleteVirtualNetworkResult = (HttpResponseDecorator) azureClient.deleteVirtualNetwork(props);
            String requestId = (String) azureClient.getRequestId(deleteVirtualNetworkResult);
            boolean finished = azureClient.waitUntilComplete(requestId);
        } catch (HttpResponseException ex) {
            httpResponseExceptionHandler(ex, resource.getResourceName(), stack.getOwner(), stack);
        } catch (Exception ex) {
            throw new InternalServerException(ex.getMessage());
        }
View Full Code Here

TOP

Related Classes of com.sequenceiq.cloud.azure.client.AzureClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.