use of com.sequenceiq.cloudbreak.cloud.model.CloudNetworks in project cloudbreak by hortonworks.
the class PlatformParameterV1Controller method getCloudNetworks.
@Override
public PlatformNetworksResponse getCloudNetworks(PlatformResourceRequestJson resourceRequestJson) {
resourceRequestJson = prepareAccountAndOwner(resourceRequestJson, authenticatedUserService.getCbUser());
PlatformResourceRequest convert = conversionService.convert(resourceRequestJson, PlatformResourceRequest.class);
CloudNetworks cloudNetworks = cloudParameterService.getCloudNetworks(convert.getCredential(), convert.getRegion(), convert.getPlatformVariant(), convert.getFilters());
return conversionService.convert(cloudNetworks, PlatformNetworksResponse.class);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudNetworks in project cloudbreak by hortonworks.
the class AwsPlatformResources method networks.
@Override
public CloudNetworks networks(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
Map<String, Set<CloudNetwork>> result = new HashMap<>();
Set<CloudNetwork> cloudNetworks = new HashSet<>();
AmazonEC2Client ec2Client = awsClient.createAccess(new AwsCredentialView(cloudCredential), region.value());
// create vpc filter view
PlatformResourceVpcFilterView filter = new PlatformResourceVpcFilterView(filters);
DescribeVpcsRequest describeVpcsRequest = new DescribeVpcsRequest();
// If the filtervalue is provided then we should filter only for those vpc
if (!Strings.isNullOrEmpty(filter.getVpcId())) {
describeVpcsRequest.withVpcIds(filter.getVpcId());
}
for (Vpc vpc : ec2Client.describeVpcs(describeVpcsRequest).getVpcs()) {
Map<String, String> subnetMap = new HashMap<>();
List<Subnet> subnets = ec2Client.describeSubnets(createVpcDescribeRequest(vpc)).getSubnets();
Map<String, Object> properties = new HashMap<>();
properties.put("cidrBlock", vpc.getCidrBlock());
properties.put("default", vpc.getIsDefault());
properties.put("dhcpOptionsId", vpc.getDhcpOptionsId());
properties.put("instanceTenancy", vpc.getInstanceTenancy());
properties.put("state", vpc.getState());
for (Subnet subnet : subnets) {
subnetMap.put(subnet.getSubnetId(), subnet.getSubnetId());
}
cloudNetworks.add(new CloudNetwork(vpc.getVpcId(), vpc.getVpcId(), subnetMap, properties));
}
result.put(region.value(), cloudNetworks);
return new CloudNetworks(result);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudNetworks in project cloudbreak by hortonworks.
the class GcpPlatformResources method networks.
@Override
public CloudNetworks networks(CloudCredential cloudCredential, Region region, Map<String, String> filters) throws Exception {
Compute compute = GcpStackUtil.buildCompute(cloudCredential);
String projectId = GcpStackUtil.getProjectId(cloudCredential);
Map<String, Set<CloudNetwork>> result = new HashMap<>();
Set<CloudNetwork> cloudNetworks = new HashSet<>();
if (compute != null) {
NetworkList networkList = compute.networks().list(projectId).execute();
List<Subnetwork> subnetworkList = compute.subnetworks().list(projectId, region.value()).execute().getItems();
for (Network network : networkList.getItems()) {
Map<String, Object> properties = new HashMap<>();
properties.put("gatewayIPv4", Strings.nullToEmpty(network.getGatewayIPv4()));
properties.put("description", Strings.nullToEmpty(network.getDescription()));
properties.put("IPv4Range", Strings.nullToEmpty(network.getIPv4Range()));
properties.put("creationTimestamp", Strings.nullToEmpty(network.getCreationTimestamp()));
Map<String, String> subnets = new HashMap<>();
if (subnetworkList != null && network.getSubnetworks() != null) {
for (Subnetwork subnetwork : subnetworkList) {
if (network.getSubnetworks().contains(subnetwork.getSelfLink())) {
subnets.put(subnetwork.getName(), subnetwork.getName());
}
}
}
CloudNetwork cloudNetwork = new CloudNetwork(network.getName(), network.getId().toString(), subnets, properties);
cloudNetworks.add(cloudNetwork);
}
result.put(region.value(), cloudNetworks);
}
return new CloudNetworks(result);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudNetworks in project cloudbreak by hortonworks.
the class OpenStackPlatformResources method networks.
@Override
public CloudNetworks networks(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
OSClient<?> osClient = openStackClient.createOSClient(cloudCredential);
KeystoneCredentialView osCredential = openStackClient.createKeystoneCredential(cloudCredential);
Set<CloudNetwork> cloudNetworks = new HashSet<>();
List<? extends Network> networks = getNetworks(osClient);
for (Network network : networks) {
Map<String, Object> properties = new HashMap<>();
properties.put("networkType", network.getNetworkType());
properties.put("providerPhyNet", network.getProviderPhyNet());
properties.put("providerSegID", network.getProviderSegID());
properties.put("tenantId", network.getTenantId());
Map<String, String> subnets = new HashMap<>();
List<? extends Subnet> neutronSubnets = network.getNeutronSubnets();
LOGGER.info("neutron subnets for {}: {}", network.getName(), neutronSubnets);
if (neutronSubnets != null) {
for (Subnet neutronSubnet : neutronSubnets) {
if (neutronSubnet != null) {
subnets.put(neutronSubnet.getId(), neutronSubnet.getName());
}
}
}
CloudNetwork cloudNetwork = new CloudNetwork(network.getName(), network.getId(), subnets, properties);
cloudNetworks.add(cloudNetwork);
}
Map<String, Set<CloudNetwork>> result = new HashMap<>(1);
result.put(region.value() == null ? osCredential.getTenantName() : region.value(), cloudNetworks);
LOGGER.info("openstack cloud networks result: {}", result);
return new CloudNetworks(result);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudNetworks in project cloudbreak by hortonworks.
the class GetPlatformNetworksHandler method accept.
@Override
public void accept(Event<GetPlatformNetworksRequest> getPlatformNetworksRequest) {
LOGGER.info("Received event: {}", getPlatformNetworksRequest);
GetPlatformNetworksRequest request = getPlatformNetworksRequest.getData();
try {
CloudPlatformVariant cloudPlatformVariant = new CloudPlatformVariant(Platform.platform(request.getExtendedCloudCredential().getCloudPlatform()), Variant.variant(request.getVariant()));
CloudNetworks networks = cloudPlatformConnectors.get(cloudPlatformVariant).platformResources().networks(request.getCloudCredential(), Region.region(request.getRegion()), request.getFilters());
GetPlatformNetworksResult getPlatformNetworksResult = new GetPlatformNetworksResult(request, networks);
request.getResult().onNext(getPlatformNetworksResult);
LOGGER.info("Query platform networks types finished.");
} catch (Exception e) {
request.getResult().onNext(new GetPlatformNetworksResult(e.getMessage(), e, request));
}
}
Aggregations