Search in sources :

Example 16 with CloudResourceStatus

use of com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus in project cloudbreak by hortonworks.

the class ResourceStatusLists method aggregate.

public static CloudResourceStatus aggregate(Iterable<CloudResourceStatus> cloudResourceStatuses) {
    ResourceStatus status = null;
    StringBuilder statusReason = new StringBuilder();
    for (CloudResourceStatus crs : cloudResourceStatuses) {
        ResourceStatus currentStatus = crs.getStatus();
        if (status == null) {
            status = currentStatus;
        }
        switch(currentStatus) {
            case FAILED:
                status = currentStatus;
                statusReason.append(crs.getStatusReason()).append('\n');
                break;
            default:
                if (currentStatus.isTransient()) {
                    status = currentStatus;
                }
        }
    }
    if (status == null) {
        status = ResourceStatus.FAILED;
        statusReason.append("Resources does not have any state");
    }
    return new CloudResourceStatus(null, status, statusReason.toString());
}
Also used : CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) ResourceStatus(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)

Example 17 with CloudResourceStatus

use of com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus in project cloudbreak by hortonworks.

the class LaunchStackComponentTest method testLaunchStack.

@Test
public void testLaunchStack() {
    LaunchStackResult lsr = sendCloudRequest();
    List<CloudResourceStatus> r = lsr.getResults();
    assertEquals(ResourceStatus.CREATED, r.get(0).getStatus());
    assertNull(lsr.getErrorDetails());
}
Also used : CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) LaunchStackResult(com.sequenceiq.cloudbreak.cloud.event.resource.LaunchStackResult) Test(org.junit.Test)

Example 18 with CloudResourceStatus

use of com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus in project cloudbreak by hortonworks.

the class TestApplicationContext method cloudConnectors.

@Bean
public CloudConnector cloudConnectors() throws Exception {
    CloudResource resource = new Builder().type(ResourceType.HEAT_STACK).name("ref").build();
    when(cloudConnector.authentication()).thenReturn(authenticator);
    when(cloudConnector.credentials()).thenReturn(credentialConnector);
    when(credentialConnector.create(any(AuthenticatedContext.class))).thenReturn(new CloudCredentialStatus(null, CredentialStatus.CREATED));
    when(credentialConnector.delete(any(AuthenticatedContext.class))).thenReturn(new CloudCredentialStatus(null, CredentialStatus.DELETED));
    when(authenticator.authenticate(any(), any())).thenReturn(g.createAuthenticatedContext());
    when(cloudConnector.platform()).thenReturn(Platform.platform("TESTCONNECTOR"));
    when(cloudConnector.variant()).thenReturn(Variant.variant("TESTVARIANT"));
    when(cloudConnector.resources()).thenReturn(resourceConnector);
    when(cloudConnector.instances()).thenReturn(instanceConnector);
    when(cloudConnector.metadata()).thenReturn(collector);
    when(resourceConnector.launch(any(), any(), any(), any(), anyLong())).thenReturn(Collections.singletonList(new CloudResourceStatus(resource, ResourceStatus.CREATED)));
    when(resourceConnector.terminate(any(), any(), any())).thenReturn(Collections.singletonList(new CloudResourceStatus(resource, ResourceStatus.DELETED)));
    when(resourceConnector.update(any(), any(), any())).thenReturn(Collections.singletonList(new CloudResourceStatus(resource, ResourceStatus.UPDATED)));
    when(resourceConnector.upscale(any(), any(), any())).thenReturn(Collections.singletonList(new CloudResourceStatus(resource, ResourceStatus.UPDATED)));
    when(resourceConnector.downscale(any(), any(), any(), anyList(), anyMap())).thenReturn(Collections.singletonList(new CloudResourceStatus(resource, ResourceStatus.UPDATED)));
    when(instanceConnector.check(any(), any())).thenReturn(Collections.singletonList(new CloudVmInstanceStatus(cloudInstance, InstanceStatus.STARTED)));
    CloudVmInstanceStatus collectInstanceStatus = new CloudVmInstanceStatus(cloudInstance, InstanceStatus.IN_PROGRESS);
    when(collector.collect(any(), any(), any())).thenReturn(Collections.singletonList(new CloudVmMetaDataStatus(collectInstanceStatus, new CloudInstanceMetaData("privateIp", "publicIp", "hypervisor"))));
    when(instanceConnector.start(any(), any(), any())).thenReturn(Collections.singletonList(new CloudVmInstanceStatus(cloudInstance, InstanceStatus.STARTED)));
    when(instanceConnector.stop(any(), any(), any())).thenReturn(Collections.singletonList(new CloudVmInstanceStatus(cloudInstance, InstanceStatus.STOPPED)));
    when(instanceConnector.getConsoleOutput(any(), eq(cloudInstance))).thenReturn(g.getSshFingerprint() + "    RSA/n-----END SSH HOST KEY FINGERPRINTS-----");
    when(instanceConnector.getConsoleOutput(any(), eq(cloudInstanceBad))).thenReturn("XYZ    RSA/n-----END SSH HOST KEY FINGERPRINTS-----");
    return cloudConnector;
}
Also used : CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) Builder(com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudCredentialStatus(com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus) Bean(org.springframework.context.annotation.Bean)

Example 19 with CloudResourceStatus

use of com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus in project cloudbreak by hortonworks.

the class AbstractResourceConnector method update.

@Override
public List<CloudResourceStatus> update(AuthenticatedContext auth, CloudStack stack, List<CloudResource> resources) throws Exception {
    CloudContext cloudContext = auth.getCloudContext();
    Platform platform = cloudContext.getPlatform();
    // context
    ResourceBuilderContext context = contextBuilders.get(platform).contextInit(cloudContext, auth, stack.getNetwork(), resources, true);
    // group
    List<CloudResource> groupResources = groupResourceService.getGroupResources(platform, resources);
    List<CloudResourceStatus> groupStatuses = groupResourceService.update(context, auth, stack.getNetwork(), stack.getCloudSecurity(), groupResources);
    // network
    List<CloudResource> networkResources = networkResourceService.getNetworkResources(platform, resources);
    List<CloudResourceStatus> networkStatuses = networkResourceService.update(context, auth, stack.getNetwork(), stack.getCloudSecurity(), networkResources);
    groupStatuses.addAll(networkStatuses);
    return groupStatuses;
}
Also used : Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ResourceBuilderContext(com.sequenceiq.cloudbreak.cloud.template.context.ResourceBuilderContext) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Example 20 with CloudResourceStatus

use of com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus in project cloudbreak by hortonworks.

the class AbstractResourceConnector method launch.

@Override
public List<CloudResourceStatus> launch(AuthenticatedContext auth, CloudStack stack, PersistenceNotifier notifier, AdjustmentType adjustmentType, Long threshold) throws Exception {
    CloudContext cloudContext = auth.getCloudContext();
    Platform platform = cloudContext.getPlatform();
    // context
    ResourceBuilderContext context = contextBuilders.get(platform).contextInit(cloudContext, auth, stack.getNetwork(), null, true);
    // network
    List<CloudResourceStatus> cloudResourceStatuses = networkResourceService.buildResources(context, auth, stack.getNetwork(), stack.getCloudSecurity());
    context.addNetworkResources(getCloudResources(cloudResourceStatuses));
    // group
    List<CloudResourceStatus> groupStatuses = groupResourceService.buildResources(context, auth, stack.getGroups(), stack.getNetwork(), stack.getCloudSecurity());
    cloudResourceStatuses.addAll(groupStatuses);
    // compute
    List<CloudResourceStatus> computeStatuses = computeResourceService.buildResourcesForLaunch(context, auth, stack.getGroups(), stack.getImage(), stack.getTags(), adjustmentType, threshold);
    cloudResourceStatuses.addAll(computeStatuses);
    return cloudResourceStatuses;
}
Also used : Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ResourceBuilderContext(com.sequenceiq.cloudbreak.cloud.template.context.ResourceBuilderContext)

Aggregations

CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)43 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)29 ArrayList (java.util.ArrayList)18 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)14 List (java.util.List)11 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)9 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)7 Builder (com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder)6 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)5 ResourceStatus (com.sequenceiq.cloudbreak.cloud.model.ResourceStatus)5 ResourcesStatePollerResult (com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult)5 Group (com.sequenceiq.cloudbreak.cloud.model.Group)4 Platform (com.sequenceiq.cloudbreak.cloud.model.Platform)4 NetworkResourceBuilder (com.sequenceiq.cloudbreak.cloud.template.NetworkResourceBuilder)4 CloudException (com.microsoft.azure.CloudException)3 Deployment (com.microsoft.azure.management.resources.Deployment)3 AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)3 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)3 ComputeResourceBuilder (com.sequenceiq.cloudbreak.cloud.template.ComputeResourceBuilder)3 ResourceBuilderContext (com.sequenceiq.cloudbreak.cloud.template.context.ResourceBuilderContext)3