Search in sources :

Example 1 with DeploymentExportResult

use of com.microsoft.azure.management.resources.DeploymentExportResult in project azure-tools-for-java by Microsoft.

the class DeploymentPropertyViewPresenter method onLoadProperty.

public void onLoadProperty(DeploymentNode node) {
    Observable.fromCallable(() -> {
        List<String> parameters = new ArrayList<>();
        List<String> variables = new ArrayList<>();
        List<String> resources = new ArrayList<>();
        Deployment deployment = node.getDeployment();
        DeploymentExportResult template = deployment.exportTemplate();
        Map<String, Object> templateObj = (Map<String, Object>) template.template();
        if (templateObj.get("parameters") != null) {
            Map<String, Map<String, String>> parametersTmp = (Map<String, Map<String, String>>) templateObj.get("parameters");
            for (String parameter : parametersTmp.keySet()) {
                parameters.add(String.format("%s(%s)", parameter, parametersTmp.get(parameter).get("type")));
            }
        }
        if (templateObj.get("variables") != null) {
            Map<String, Map<String, String>> variablesTmp = (Map<String, Map<String, String>>) templateObj.get("variables");
            for (String variable : variablesTmp.keySet()) {
                variables.add(variable);
            }
        }
        if (templateObj.get("resources") != null) {
            List<Map<String, String>> resourcesTmp = (List<Map<String, String>>) templateObj.get("resources");
            for (Map<String, String> resource : resourcesTmp) {
                resources.add(String.format("%s(%s)", resource.get("name"), resource.get("type")));
            }
        }
        return new DeploymentProperty(deployment, parameters, variables, resources, template.templateAsJson());
    }).subscribeOn(this.getSchedulerProvider().io()).subscribe((property) -> {
        DefaultLoader.getIdeHelper().invokeLater(() -> {
            if (!this.isViewDetached()) {
                getMvpView().onLoadProperty(property);
            }
        });
    }, (e) -> {
        DefaultLoader.getIdeHelper().invokeLater(() -> {
            if (!this.isViewDetached()) {
                DefaultLoader.getUIHelper().logError("An exception occurred when load deployment properties", e);
                DefaultLoader.getUIHelper().showError(node, "An exception occurred when load deployment properties, " + e.getMessage());
            }
        });
    });
}
Also used : ArrayList(java.util.ArrayList) DeploymentExportResult(com.microsoft.azure.management.resources.DeploymentExportResult) Deployment(com.microsoft.azure.management.resources.Deployment) DeploymentProperty(com.microsoft.azuretools.core.mvp.ui.arm.DeploymentProperty) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 2 with DeploymentExportResult

use of com.microsoft.azure.management.resources.DeploymentExportResult in project cloudbreak by hortonworks.

the class AzureResourceConnectorTest method setUp.

@Before
public void setUp() {
    DeploymentExportResult deploymentExportResult = mock(DeploymentExportResult.class);
    Group group = mock(Group.class);
    AzureStackView azureStackView = mock(AzureStackView.class);
    groups = List.of(group);
    CloudResource cloudResource = mock(CloudResource.class);
    instances = List.of(cloudResource);
    network = new Network(new Subnet("0.0.0.0/16"));
    AzureImage image = new AzureImage("id", "name", true);
    imageModel = new Image(IMAGE_NAME, new HashMap<>(), "centos7", "redhat7", "", "default", "default-id", new HashMap<>());
    when(stack.getGroups()).thenReturn(groups);
    when(stack.getNetwork()).thenReturn(network);
    when(stack.getImage()).thenReturn(imageModel);
    when(ac.getCloudContext()).thenReturn(cloudContext);
    when(ac.getParameter(AzureClient.class)).thenReturn(client);
    when(ac.getCloudCredential()).thenReturn(new CloudCredential("aCredentialId", "aCredentialName", "account"));
    when(azureUtils.getStackName(cloudContext)).thenReturn(STACK_NAME);
    when(azureStorage.getCustomImage(any(), any(), any())).thenReturn(image);
    when(deployment.exportTemplate()).thenReturn(deploymentExportResult);
    when(azureResourceGroupMetadataProvider.getResourceGroupName(cloudContext, stack)).thenReturn(RESOURCE_GROUP_NAME);
    when(azureCloudResourceService.getDeploymentCloudResources(deployment)).thenReturn(instances);
    when(azureCloudResourceService.getInstanceCloudResources(STACK_NAME, instances, groups, RESOURCE_GROUP_NAME)).thenReturn(instances);
    when(azureStackViewProvider.getAzureStack(any(), eq(stack), eq(client), eq(ac))).thenReturn(azureStackView);
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) HashMap(java.util.HashMap) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Network(com.sequenceiq.cloudbreak.cloud.model.Network) DeploymentExportResult(com.microsoft.azure.management.resources.DeploymentExportResult) AzureStackView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Subnet(com.sequenceiq.cloudbreak.cloud.model.Subnet) Image(com.sequenceiq.cloudbreak.cloud.model.Image) Before(org.junit.Before)

Example 3 with DeploymentExportResult

use of com.microsoft.azure.management.resources.DeploymentExportResult in project azure-tools-for-java by microsoft.

the class DeploymentPropertyViewPresenter method onLoadProperty.

public void onLoadProperty(DeploymentNode node) {
    Observable.fromCallable(() -> {
        List<String> parameters = new ArrayList<>();
        List<String> variables = new ArrayList<>();
        List<String> resources = new ArrayList<>();
        Deployment deployment = node.getDeployment();
        DeploymentExportResult template = deployment.exportTemplate();
        Map<String, Object> templateObj = (Map<String, Object>) template.template();
        if (templateObj.get("parameters") != null) {
            Map<String, Map<String, String>> parametersTmp = (Map<String, Map<String, String>>) templateObj.get("parameters");
            for (String parameter : parametersTmp.keySet()) {
                parameters.add(String.format("%s(%s)", parameter, parametersTmp.get(parameter).get("type")));
            }
        }
        if (templateObj.get("variables") != null) {
            Map<String, Map<String, String>> variablesTmp = (Map<String, Map<String, String>>) templateObj.get("variables");
            for (String variable : variablesTmp.keySet()) {
                variables.add(variable);
            }
        }
        if (templateObj.get("resources") != null) {
            List<Map<String, String>> resourcesTmp = (List<Map<String, String>>) templateObj.get("resources");
            for (Map<String, String> resource : resourcesTmp) {
                resources.add(String.format("%s(%s)", resource.get("name"), resource.get("type")));
            }
        }
        return new DeploymentProperty(deployment, parameters, variables, resources, template.templateAsJson());
    }).subscribeOn(this.getSchedulerProvider().io()).subscribe((property) -> {
        DefaultLoader.getIdeHelper().invokeLater(() -> {
            if (!this.isViewDetached()) {
                getMvpView().onLoadProperty(property);
            }
        });
    }, (e) -> {
        DefaultLoader.getIdeHelper().invokeLater(() -> {
            if (!this.isViewDetached()) {
                DefaultLoader.getUIHelper().logError("An exception occurred when load deployment properties", e);
                DefaultLoader.getUIHelper().showError(node, "An exception occurred when load deployment properties, " + e.getMessage());
            }
        });
    });
}
Also used : ArrayList(java.util.ArrayList) DeploymentExportResult(com.microsoft.azure.management.resources.DeploymentExportResult) Deployment(com.microsoft.azure.management.resources.Deployment) DeploymentProperty(com.microsoft.azuretools.core.mvp.ui.arm.DeploymentProperty) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map)

Aggregations

DeploymentExportResult (com.microsoft.azure.management.resources.DeploymentExportResult)3 Deployment (com.microsoft.azure.management.resources.Deployment)2 DeploymentProperty (com.microsoft.azuretools.core.mvp.ui.arm.DeploymentProperty)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 AzureStackView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView)1 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)1 Group (com.sequenceiq.cloudbreak.cloud.model.Group)1 Image (com.sequenceiq.cloudbreak.cloud.model.Image)1 Network (com.sequenceiq.cloudbreak.cloud.model.Network)1 Subnet (com.sequenceiq.cloudbreak.cloud.model.Subnet)1 HashMap (java.util.HashMap)1 Before (org.junit.Before)1