use of com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder in project cloudbreak by hortonworks.
the class GcpSubnetResourceBuilder method build.
@Override
public CloudResource build(GcpContext context, AuthenticatedContext auth, Network network, Security security, CloudResource resource) throws Exception {
if (isNewNetworkAndSubnet(network) || isNewSubnetInExistingNetwork(network)) {
Compute compute = context.getCompute();
String projectId = context.getProjectId();
Subnetwork gcpSubnet = new Subnetwork();
gcpSubnet.setName(resource.getName());
gcpSubnet.setIpCidrRange(network.getSubnet().getCidr());
String networkName = context.getStringParameter(GcpNetworkResourceBuilder.NETWORK_NAME);
gcpSubnet.setNetwork(String.format("https://www.googleapis.com/compute/v1/projects/%s/global/networks/%s", projectId, networkName));
Insert snInsert = compute.subnetworks().insert(projectId, auth.getCloudContext().getLocation().getRegion().value(), gcpSubnet);
try {
Operation operation = snInsert.execute();
if (operation.getHttpErrorStatusCode() != null) {
throw new GcpResourceException(operation.getHttpErrorMessage(), resourceType(), resource.getName());
}
context.putParameter(SUBNET_NAME, resource.getName());
return createOperationAwareCloudResource(resource, operation);
} catch (GoogleJsonResponseException e) {
throw new GcpResourceException(checkException(e), resourceType(), resource.getName());
}
}
context.putParameter(SUBNET_NAME, resource.getName());
return new Builder().cloudResource(resource).persistent(false).build();
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder in project cloudbreak by hortonworks.
the class GcpInstanceResourceBuilderTest method setUp.
@Before
public void setUp() {
privateId = 0L;
name = "master";
flavor = "m1.medium";
instanceId = "SOME_ID";
volumes = Arrays.asList(new Volume("/hadoop/fs1", "HDD", 1), new Volume("/hadoop/fs2", "HDD", 1));
List<SecurityRule> rules = Collections.singletonList(new SecurityRule("0.0.0.0/0", new PortDefinition[] { new PortDefinition("22", "22"), new PortDefinition("443", "443") }, "tcp"));
security = new Security(rules, null);
Location location = Location.location(Region.region("region"), AvailabilityZone.availabilityZone("az"));
Map<InstanceGroupType, String> userData = ImmutableMap.of(InstanceGroupType.CORE, "CORE", InstanceGroupType.GATEWAY, "GATEWAY");
image = new Image("cb-centos66-amb200-2015-05-25", userData, "redhat6", "", "default", "default-id");
CloudContext cloudContext = new CloudContext(privateId, "testname", "GCP", "owner");
CloudCredential cloudCredential = new CloudCredential(privateId, "credentialname");
cloudCredential.putParameter("projectId", "projectId");
String projectId = GcpStackUtil.getProjectId(cloudCredential);
String serviceAccountId = GcpStackUtil.getServiceAccountId(cloudCredential);
authenticatedContext = new AuthenticatedContext(cloudContext, cloudCredential);
context = new GcpContext(cloudContext.getName(), location, projectId, serviceAccountId, compute, false, 30, false);
List<CloudResource> networkResources = Arrays.asList(new Builder().type(ResourceType.GCP_NETWORK).name("network-test").build());
context.addNetworkResources(networkResources);
operation = new Operation();
operation.setName("operation");
operation.setHttpErrorStatusCode(null);
GcpResourceNameService resourceNameService = new GcpResourceNameService();
ReflectionTestUtils.setField(resourceNameService, "maxResourceNameLength", 50);
ReflectionTestUtils.setField(builder, "resourceNameService", resourceNameService);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder in project cloudbreak by hortonworks.
the class OpenStackResourceConnector method launch.
@SuppressWarnings("unchecked")
@Override
public List<CloudResourceStatus> launch(AuthenticatedContext authenticatedContext, CloudStack stack, PersistenceNotifier notifier, AdjustmentType adjustmentType, Long threshold) {
String stackName = utils.getStackName(authenticatedContext);
NeutronNetworkView neutronNetworkView = new NeutronNetworkView(stack.getNetwork());
boolean existingNetwork = neutronNetworkView.isExistingNetwork();
String existingSubnetCidr = getExistingSubnetCidr(authenticatedContext, stack);
ModelContext modelContext = new ModelContext();
modelContext.withExistingNetwork(existingNetwork);
modelContext.withExistingSubnet(existingSubnetCidr != null);
modelContext.withGroups(stack.getGroups());
modelContext.withInstanceUserData(stack.getImage());
modelContext.withLocation(authenticatedContext.getCloudContext().getLocation());
modelContext.withStackName(stackName);
modelContext.withNeutronNetworkView(neutronNetworkView);
modelContext.withTemplateString(stack.getTemplate());
modelContext.withTags(stack.getTags());
String heatTemplate = heatTemplateBuilder.build(modelContext);
Map<String, String> parameters = heatTemplateBuilder.buildParameters(authenticatedContext, stack, existingNetwork, existingSubnetCidr);
OSClient<?> client = openStackClient.createOSClient(authenticatedContext);
List<CloudResourceStatus> resources;
Stack existingStack = client.heat().stacks().getStackByName(stackName);
if (existingStack == null) {
if (stack.getInstanceAuthentication().getPublicKeyId() == null) {
createKeyPair(authenticatedContext, stack, client);
}
Stack heatStack = client.heat().stacks().create(Builders.stack().name(stackName).template(heatTemplate).disableRollback(false).parameters(parameters).timeoutMins(OPERATION_TIMEOUT).build());
List<CloudResource> cloudResources = collectResources(authenticatedContext, notifier, heatStack, stack, neutronNetworkView);
resources = check(authenticatedContext, cloudResources);
} else {
LOGGER.info("Heat stack already exists: {}", existingStack.getName());
CloudResource cloudResource = new Builder().type(ResourceType.HEAT_STACK).name(existingStack.getId()).build();
resources = Collections.singletonList(new CloudResourceStatus(cloudResource, ResourceStatus.CREATED));
}
LOGGER.debug("Launched resources: {}", resources);
return resources;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder in project cloudbreak by hortonworks.
the class MockResourceConnector method launch.
@Override
public List<CloudResourceStatus> launch(AuthenticatedContext authenticatedContext, CloudStack stack, PersistenceNotifier persistenceNotifier, AdjustmentType adjustmentType, Long threshold) {
List<CloudResourceStatus> cloudResourceStatuses = new ArrayList<>();
for (Group group : stack.getGroups()) {
for (int i = 0; i < group.getInstancesSize(); i++) {
CloudResource cloudResource = new Builder().type(ResourceType.MOCK_INSTANCE).status(CommonStatus.CREATED).name("cloudinstance" + cloudResourceStatuses.size()).reference("").persistent(true).build();
cloudResourceStatuses.add(new CloudResourceStatus(cloudResource, CREATED));
}
}
return cloudResourceStatuses;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder 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;
}
Aggregations