You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ra...@apache.org on 2015/08/21 09:10:03 UTC
[50/52] [abbrv] [partial] stratos git commit: Merging jclouds GCE fix
with upstream - resolving conflicts
http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/gce/GCEIaas.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/gce/GCEIaas.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/gce/GCEIaas.java
index 0822902..7b60b71 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/gce/GCEIaas.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/gce/GCEIaas.java
@@ -38,23 +38,23 @@ import org.apache.stratos.cloud.controller.iaases.PartitionValidator;
import org.apache.stratos.cloud.controller.util.CloudControllerConstants;
import org.apache.stratos.cloud.controller.util.ComputeServiceBuilderUtil;
import org.jclouds.ContextBuilder;
-import org.jclouds.collect.IterableWithMarker;
import org.jclouds.compute.ComputeService;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder;
-import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.domain.Location;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
-import org.jclouds.googlecomputeengine.domain.*;
+import org.jclouds.googlecomputeengine.compute.options.GoogleComputeEngineTemplateOptions;
+import org.jclouds.googlecomputeengine.domain.AttachDisk;
+import org.jclouds.googlecomputeengine.domain.Disk;
+import org.jclouds.googlecomputeengine.domain.Instance;
+import org.jclouds.googlecomputeengine.domain.Operation;
import org.jclouds.googlecomputeengine.features.DiskApi;
import org.jclouds.googlecomputeengine.features.InstanceApi;
-import org.jclouds.googlecomputeengine.features.RegionApi;
-import org.jclouds.googlecomputeengine.features.ZoneApi;
-import org.jclouds.googlecomputeengine.options.AttachDiskOptions;
-import org.jclouds.googlecomputeengine.options.AttachDiskOptions.DiskType;
+import org.jclouds.googlecomputeengine.options.DiskCreationOptions;
+import java.net.URI;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
@@ -62,11 +62,8 @@ import static java.util.concurrent.TimeUnit.SECONDS;
import static org.jclouds.util.Predicates2.retry;
public class GCEIaas extends JcloudsIaas {
-
-
private static final Log log = LogFactory.getLog(GCEIaas.class);
-
- private static final String PROJECTNAME = "projectName";
+ public static final int MAX_WAIT_TIME = 60; // seconds
public GCEIaas(IaasProvider iaasProvider) {
super(iaasProvider);
@@ -92,10 +89,10 @@ public class GCEIaas extends JcloudsIaas {
throw new CloudControllerException(msg);
}
- log.info("gce buildTemplate");
-
- TemplateBuilder templateBuilder = iaasInfo.getComputeService()
- .templateBuilder();
+ if (log.isDebugEnabled()) {
+ log.debug("Building template for Google Compute Engine IaaS");
+ }
+ TemplateBuilder templateBuilder = iaasInfo.getComputeService().templateBuilder();
// set image id specified
templateBuilder.imageId(iaasInfo.getImage());
@@ -107,8 +104,7 @@ public class GCEIaas extends JcloudsIaas {
if (location.getScope().toString().equalsIgnoreCase(CloudControllerConstants.ZONE_ELEMENT) &&
location.getId().equals(zone)) {
templateBuilder.locationId(location.getId());
- log.info("ZONE has been set as " + zone
- + " with id: " + location.getId());
+ log.info("zone has been set as " + zone + " with id: " + location.getId());
break;
}
}
@@ -118,14 +114,14 @@ public class GCEIaas extends JcloudsIaas {
// set instance type eg: m1.large
templateBuilder.hardwareId(iaasInfo.getProperty(CloudControllerConstants.INSTANCE_TYPE));
}
-
// build the Template
Template template = templateBuilder.build();
if (zone != null) {
if (!template.getLocation().getId().equals(zone)) {
- log.warn("couldn't find assignable ZONE of id :" + zone +
- " in the IaaS. Hence using the default location as " + template.getLocation().getScope().toString() +
+ log.warn("couldn't find assignable zone of id :" + zone +
+ " in the IaaS. Hence using the default location as " +
+ template.getLocation().getScope().toString() +
" with the id " + template.getLocation().getId());
}
}
@@ -135,15 +131,11 @@ public class GCEIaas extends JcloudsIaas {
// wish to assign IPs manually, it can be non-blocking.
// is auto-assign-ip mode or manual-assign-ip mode? - default mode is
// non-blocking
- boolean blockUntilRunning = Boolean.parseBoolean(iaasInfo
- .getProperty("autoAssignIp"));
- template.getOptions().as(TemplateOptions.class)
- .blockUntilRunning(blockUntilRunning);
+ boolean blockUntilRunning = Boolean.parseBoolean(iaasInfo.getProperty("autoAssignIp"));
+ template.getOptions().as(GoogleComputeEngineTemplateOptions.class).blockUntilRunning(blockUntilRunning);
- // this is required in order to avoid creation of additional security
- // groups by Jclouds.
- template.getOptions().as(TemplateOptions.class)
- .inboundPorts(22, 80, 8080, 443, 8243);
+ // this is required in order to avoid creation of additional security groups by Jclouds.
+ template.getOptions().as(GoogleComputeEngineTemplateOptions.class).inboundPorts(22, 80, 8080, 443, 8243);
if (zone != null) {
templateBuilder.locationId(zone);
@@ -155,10 +147,9 @@ public class GCEIaas extends JcloudsIaas {
for (String propertyKey : iaasInfo.getProperties().keySet()) {
if (propertyKey.startsWith(CloudControllerConstants.TAGS_AS_KEY_VALUE_PAIRS_PREFIX)) {
- keyValuePairTagsMap.put(propertyKey.substring(CloudControllerConstants.TAGS_AS_KEY_VALUE_PAIRS_PREFIX.length()),
- iaasInfo.getProperties().get(propertyKey));
- template.getOptions()
- .userMetadata(keyValuePairTagsMap);
+ keyValuePairTagsMap.put(propertyKey.substring(CloudControllerConstants.TAGS_AS_KEY_VALUE_PAIRS_PREFIX
+ .length()), iaasInfo.getProperties().get(propertyKey));
+ template.getOptions().as(GoogleComputeEngineTemplateOptions.class).userMetadata(keyValuePairTagsMap);
}
log.info("usermeta data key:" + propertyKey + " value: " + iaasInfo.getProperties().get(propertyKey));
}
@@ -169,7 +160,7 @@ public class GCEIaas extends JcloudsIaas {
networks.add(ni.getNetworkUuid());
log.info("using network interface " + ni.getNetworkUuid());
}
- template.getOptions().as(TemplateOptions.class).networks(networks);
+ template.getOptions().as(GoogleComputeEngineTemplateOptions.class).networks(networks);
log.info("using network interface " + networks);
}
@@ -227,25 +218,15 @@ public class GCEIaas extends JcloudsIaas {
@Override
public boolean isValidRegion(String region) throws InvalidRegionException {
IaasProvider iaasInfo = getIaasProvider();
-
if (region == null || iaasInfo == null) {
String msg = "Region or IaaSProvider is null: region: " + region + " - IaaSProvider: " + iaasInfo;
log.error(msg);
throw new InvalidRegionException(msg);
}
-
GoogleComputeEngineApi api = getGCEApi();
- RegionApi regionApi = api.getRegionApiForProject(iaasInfo.getProperty(PROJECTNAME));
-
- for (IterableWithMarker<Region> page : regionApi.list()) {
- for (Region r : page) {
- if (region.equalsIgnoreCase(r.getName())) {
- log.debug("Found a matching region: " + region);
- return true;
- }
- }
+ if (api.regions().get(region) != null) {
+ return true;
}
-
String msg = "Invalid region: " + region + " in the iaas: " + iaasInfo.getType();
log.error(msg);
throw new InvalidRegionException(msg);
@@ -256,24 +237,16 @@ public class GCEIaas extends JcloudsIaas {
IaasProvider iaasInfo = getIaasProvider();
if (zone == null || iaasInfo == null) {
- String msg = "Zone or IaaSProvider is null: region: " + region +
- " zone: " + zone + " - IaaSProvider: " + iaasInfo;
+ String msg = "Zone or IaaSProvider is null. [region] " + region + ", [zone] " + zone + ", [IaaSProvider] "
+ + iaasInfo;
log.error(msg);
throw new InvalidZoneException(msg);
}
GoogleComputeEngineApi api = getGCEApi();
- ZoneApi zoneApi = api.getZoneApiForProject(iaasInfo.getProperty(PROJECTNAME));
-
- for (IterableWithMarker<Zone> page : zoneApi.list()) {
- for (Zone z : page) {
- if (zone.equalsIgnoreCase(z.getName())) {
- log.debug("Found a matching zone: " + zone);
- return true;
- }
- }
+ if (api.zones().get(zone) != null) {
+ return true;
}
-
String msg = "Invalid zone: " + zone + " in the region: " + region + " and of the iaas: " + iaasInfo.getType();
log.error(msg);
throw new InvalidZoneException(msg);
@@ -303,19 +276,23 @@ public class GCEIaas extends JcloudsIaas {
String diskName = "stratos-disk-" + rand.nextInt(100000);
DiskApi diskApi = getGCEDiskApi();
String zone = getZone();
-
- log.debug("Creating volume: " + diskName + " in zone: " + zone + " of size: " + sizeGB);
-
- Operation oper = diskApi.createInZone(diskName, sizeGB, zone);
-
- oper = waitGCEOperationDone(oper);
- if (oper.getStatus() != Operation.Status.DONE) {
- log.error("Failed to create volume: " + diskName + " of size: " + sizeGB +
- " in zone: " + zone + " operation: " + oper);
- return null;
+ log.info("Creating volume: " + diskName + " in zone: " + zone + " of size: " + sizeGB);
+ try {
+ DiskCreationOptions diskCreationOptions = new DiskCreationOptions.Builder().sizeGb(sizeGB).sourceSnapshot
+ (new URI(snapshotId)).build();
+ Operation oper = diskApi.create(diskName, diskCreationOptions);
+ oper = waitGCEOperationDone(oper);
+ if (!oper.status().equals(Operation.Status.DONE)) {
+ log.error("Failed to create volume: " + diskName + " of size: " + sizeGB +
+ " in zone: " + zone + " operation: " + oper);
+ return null;
+ }
+ return diskName;
}
-
- return diskName;
+ catch (Exception e) {
+ log.error("Error creating volume", e);
+ }
+ return null;
}
@Override
@@ -324,64 +301,55 @@ public class GCEIaas extends JcloudsIaas {
InstanceApi instApi = getGCEInstanceApi();
String zone = getZone();
- log.debug("Trying to attach volume: " + volumeId + " to instance: " + instanceId +
+ log.info("Trying to attach volume: " + volumeId + " to instance: " + instanceId +
" in zone: " + zone + " at devicename: " + deviceName);
- Disk disk = diskApi.getInZone(zone, volumeId);
+ Disk disk = diskApi.get(volumeId);
if (disk == null) {
log.error("Failed to get volume: " + volumeId + " in zone: " + zone);
return null;
}
-
log.debug("Found volumeId: " + volumeId + " volume: " + disk);
-
- Operation oper = instApi.attachDiskInZone(zone, instanceId,
- new AttachDiskOptions().type(DiskType.PERSISTENT)
- .source(disk.getSelfLink())
- .mode(AttachDiskOptions.DiskMode.READ_WRITE)
- .deviceName(deviceName));
- oper = waitGCEOperationDone(oper);
- if (oper.getStatus() != Operation.Status.DONE) {
- log.error("Failed to attach volume: " + volumeId + " to instance: " + instanceId +
- " in zone: " + zone + " at device: " + deviceName + " operation: " + oper);
- return null;
+ try {
+ Operation oper =
+ instApi.attachDisk(instanceId, AttachDisk.create(AttachDisk.Type.PERSISTENT, AttachDisk.Mode
+ .READ_WRITE, disk.selfLink(), deviceName, true, null, false, null, null));
+ oper = waitGCEOperationDone(oper);
+ if (!oper.status().equals(Operation.Status.DONE)) {
+ log.error("Failed to attach volume: " + volumeId + " to instance: " + instanceId +
+ " in zone: " + zone + " at device: " + deviceName + " operation: " + oper);
+ return null;
+ }
+ return volumeId;
}
-
- return volumeId;
+ catch (Exception e) {
+ log.error("Error attaching volume", e);
+ }
+ return null;
}
@Override
public void detachVolume(String instanceId, String volumeId) {
InstanceApi instApi = getGCEInstanceApi();
String zone = getZone();
- Instance inst = instApi.getInZone(zone, instanceId);
-
- log.debug("Trying to detach volume: " + volumeId + " from instance: " + instanceId +
- " " + inst + " in zone: " + zone);
-
+ Instance inst = instApi.get(instanceId);
+ log.info("Trying to detach volume: " + volumeId + " from instance: " + instanceId + " in zone: " + zone);
if (inst == null) {
log.error("Failed to find instance: " + instanceId + " in zone: " + zone);
return;
}
-
- for (Instance.AttachedDisk disk : inst.getDisks()) {
- Instance.PersistentAttachedDisk persistentDisk = (Instance.PersistentAttachedDisk) disk;
-
- log.debug("Found disk - src: " + persistentDisk.getSourceDiskName() +
- " devicename: " + persistentDisk.getDeviceName());
-
- if (persistentDisk.getSourceDiskName().equals(volumeId)) {
- Operation oper = instApi.detachDiskInZone(zone, instanceId, persistentDisk.getDeviceName().get());
+ for (Instance.AttachedDisk disk : inst.disks()) {
+ if (disk.deviceName().equals(volumeId)) {
+ log.info("Found disk to be detached. Source: " + disk.source() + " devicename: " + disk.deviceName());
+ Operation oper = instApi.detachDisk(instanceId, disk.deviceName());
oper = waitGCEOperationDone(oper);
- if (oper.getStatus() != Operation.Status.DONE) {
+ if (!oper.status().equals(Operation.Status.DONE)) {
log.error("Failed to detach volume: " + volumeId + " to instance: " + instanceId +
- " in zone: " + zone + " at device: " + persistentDisk.getDeviceName() +
- " result operation: " + oper);
+ " in zone: " + zone + " at device: " + disk.deviceName() + " result operation: " + oper);
}
return;
}
}
-
log.error("Cannot find volume: " + volumeId + " in instance: " + instanceId);
}
@@ -389,13 +357,11 @@ public class GCEIaas extends JcloudsIaas {
public void deleteVolume(String volumeId) {
DiskApi diskApi = getGCEDiskApi();
String zone = getZone();
-
- log.debug("Deleting volume: " + volumeId + " in zone: " + zone);
-
- Operation oper = diskApi.deleteInZone(zone, volumeId);
+ log.info("Deleting volume: " + volumeId + " in zone: " + zone);
+ Operation oper = diskApi.delete(volumeId);
oper = waitGCEOperationDone(oper);
- if (oper.getStatus() != Operation.Status.DONE) {
+ if (!oper.status().equals(Operation.Status.DONE)) {
log.error("Failed to delete volume: " + volumeId + " in zone: " + zone +
" operation: " + oper);
}
@@ -420,19 +386,14 @@ public class GCEIaas extends JcloudsIaas {
}
private DiskApi getGCEDiskApi() {
- IaasProvider iaasInfo = getIaasProvider();
- String projectName = iaasInfo.getProperty(PROJECTNAME);
- return getGCEApi().getDiskApiForProject(projectName);
+ return getGCEApi().disksInZone(getZone());
}
private InstanceApi getGCEInstanceApi() {
- IaasProvider iaasInfo = getIaasProvider();
- String projectName = iaasInfo.getProperty(PROJECTNAME);
- return getGCEApi().getInstanceApiForProject(projectName);
+ return getGCEApi().instancesInZone(getZone());
}
private Operation waitGCEOperationDone(Operation operation) {
- int maxWaitTime = 15; // 15 seconds
IaasProvider iaasInfo = getIaasProvider();
Injector injector = ContextBuilder.newBuilder(iaasInfo.getProvider())
.credentials(iaasInfo.getIdentity(), iaasInfo.getCredential())
@@ -441,9 +402,16 @@ public class GCEIaas extends JcloudsIaas {
injector.getInstance(Key.get(new TypeLiteral<Predicate<AtomicReference<Operation>>>() {
}, Names.named("zone")));
AtomicReference<Operation> operationReference = Atomics.newReference(operation);
- retry(zoneOperationDonePredicate, maxWaitTime, 1, SECONDS).apply(operationReference);
+ retry(zoneOperationDonePredicate, MAX_WAIT_TIME, 1, SECONDS).apply(operationReference);
return operationReference.get();
}
-}
+ @Override
+ public String getGroupName(MemberContext memberContext, byte[] payload){
+ String clusterId = memberContext.getClusterId();
+ String str = clusterId.length() > 10 ? clusterId.substring(0, 10) : clusterId.substring(0, clusterId.length());
+ String group = getIaasProvider().getName().substring(0, 4) + "-" + str.replaceAll("[^a-z0-9-]", "");
+ return group.toLowerCase();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/gce/GCEPartitionValidator.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/gce/GCEPartitionValidator.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/gce/GCEPartitionValidator.java
index 71d7aa3..2b0db62 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/gce/GCEPartitionValidator.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/gce/GCEPartitionValidator.java
@@ -22,9 +22,13 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.stratos.cloud.controller.domain.IaasProvider;
import org.apache.stratos.cloud.controller.domain.Partition;
+import org.apache.stratos.cloud.controller.exception.InvalidIaasProviderException;
import org.apache.stratos.cloud.controller.exception.InvalidPartitionException;
+import org.apache.stratos.cloud.controller.iaases.Iaas;
import org.apache.stratos.cloud.controller.iaases.PartitionValidator;
-import org.apache.stratos.cloud.controller.iaases.vcloud.VCloudPartitionValidator;
+import org.apache.stratos.cloud.controller.services.impl.CloudControllerServiceUtil;
+import org.apache.stratos.cloud.controller.util.CloudControllerConstants;
+import org.apache.stratos.cloud.controller.util.Scope;
import java.util.Properties;
@@ -34,17 +38,75 @@ import java.util.Properties;
*/
public class GCEPartitionValidator implements PartitionValidator {
- private static final Log log = LogFactory.getLog(VCloudPartitionValidator.class);
-
+ private static final Log log = LogFactory.getLog(GCEPartitionValidator.class);
private IaasProvider iaasProvider;
+ private Iaas iaas;
@Override
public IaasProvider validate(Partition partition, Properties properties) throws InvalidPartitionException {
- return iaasProvider;
+ try {
+ if (properties.containsKey(Scope.REGION.toString())) {
+ String region = properties.getProperty(Scope.REGION.toString());
+
+ if (iaasProvider.getImage() != null && !iaasProvider.getImage().contains(region)) {
+
+ String message = "Invalid partition detected, invalid region. [partition-id] " + partition.getId() +
+ ", [region] " + region;
+ log.error(message);
+ throw new InvalidPartitionException(message);
+ }
+
+ iaas.isValidRegion(region);
+
+ IaasProvider updatedIaasProvider = new IaasProvider(iaasProvider);
+ Iaas updatedIaas = CloudControllerServiceUtil.buildIaas(updatedIaasProvider);
+ updatedIaas.setIaasProvider(updatedIaasProvider);
+
+ if (properties.containsKey(Scope.ZONE.toString())) {
+ String zone = properties.getProperty(Scope.ZONE.toString());
+ iaas.isValidZone(region, zone);
+ updatedIaasProvider.setProperty(CloudControllerConstants.AVAILABILITY_ZONE, zone);
+ updatedIaas = CloudControllerServiceUtil.buildIaas(updatedIaasProvider);
+ updatedIaas.setIaasProvider(updatedIaasProvider);
+ }
+
+ updateOtherProperties(updatedIaasProvider, properties);
+ return updatedIaasProvider;
+ } else {
+ return iaasProvider;
+ }
+ }
+ catch (Exception ex) {
+ String message = "Invalid partition detected: [partition-id] " + partition.getId();
+ throw new InvalidPartitionException(message, ex);
+ }
+ }
+
+ private void updateOtherProperties(IaasProvider updatedIaasProvider, Properties properties) {
+ Iaas updatedIaas;
+ try {
+ updatedIaas = CloudControllerServiceUtil.buildIaas(updatedIaasProvider);
+
+ for (Object property : properties.keySet()) {
+ if (property instanceof String) {
+ String key = (String) property;
+ updatedIaasProvider.setProperty(key, properties.getProperty(key));
+ if (log.isDebugEnabled()) {
+ log.debug("Added property " + key + " to the IaasProvider.");
+ }
+ }
+ }
+ updatedIaas = CloudControllerServiceUtil.buildIaas(updatedIaasProvider);
+ updatedIaas.setIaasProvider(updatedIaasProvider);
+ }
+ catch (InvalidIaasProviderException ignore) {
+ }
+
}
@Override
public void setIaasProvider(IaasProvider iaasProvider) {
this.iaasProvider = iaasProvider;
+ this.iaas = iaasProvider.getIaas();
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/openstack/OpenstackPartitionValidator.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/openstack/OpenstackPartitionValidator.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/openstack/OpenstackPartitionValidator.java
index 24f8e01..a8077b8 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/openstack/OpenstackPartitionValidator.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/openstack/OpenstackPartitionValidator.java
@@ -28,7 +28,7 @@ import org.apache.stratos.cloud.controller.iaases.Iaas;
import org.apache.stratos.cloud.controller.iaases.PartitionValidator;
import org.apache.stratos.cloud.controller.services.impl.CloudControllerServiceUtil;
import org.apache.stratos.cloud.controller.util.CloudControllerConstants;
-import org.apache.stratos.messaging.domain.topology.Scope;
+import org.apache.stratos.cloud.controller.util.Scope;
import java.util.Properties;
@@ -47,8 +47,8 @@ public class OpenstackPartitionValidator implements PartitionValidator {
public IaasProvider validate(Partition partition, Properties properties) throws InvalidPartitionException {
try {
// validate the existence of the zone and hosts properties.
- if (properties.containsKey(Scope.region.toString())) {
- String region = properties.getProperty(Scope.region.toString());
+ if (properties.containsKey(Scope.REGION.toString())) {
+ String region = properties.getProperty(Scope.REGION.toString());
if (iaasProvider.getImage() != null && !iaasProvider.getImage().contains(region)) {
@@ -64,8 +64,8 @@ public class OpenstackPartitionValidator implements PartitionValidator {
Iaas updatedIaas = CloudControllerServiceUtil.buildIaas(updatedIaasProvider);
updatedIaas.setIaasProvider(updatedIaasProvider);
- if (properties.containsKey(Scope.zone.toString())) {
- String zone = properties.getProperty(Scope.zone.toString());
+ if (properties.containsKey(Scope.ZONE.toString())) {
+ String zone = properties.getProperty(Scope.ZONE.toString());
iaas.isValidZone(region, zone);
updatedIaasProvider.setProperty(CloudControllerConstants.AVAILABILITY_ZONE, zone);
http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/vcloud/VCloudIaas.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/vcloud/VCloudIaas.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/vcloud/VCloudIaas.java
deleted file mode 100644
index d87e04d..0000000
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/vcloud/VCloudIaas.java
+++ /dev/null
@@ -1,392 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.stratos.cloud.controller.iaases.vcloud;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.cloud.controller.domain.IaasProvider;
-import org.apache.stratos.cloud.controller.domain.NetworkInterface;
-import org.apache.stratos.cloud.controller.exception.CloudControllerException;
-import org.apache.stratos.cloud.controller.iaases.JcloudsIaas;
-import org.apache.stratos.cloud.controller.iaases.PartitionValidator;
-import org.apache.stratos.cloud.controller.util.ComputeServiceBuilderUtil;
-import org.jclouds.compute.ComputeService;
-import org.jclouds.compute.ComputeServiceContext;
-import org.jclouds.compute.domain.NodeMetadata;
-import org.jclouds.compute.domain.Template;
-import org.jclouds.compute.domain.TemplateBuilder;
-import org.jclouds.compute.options.TemplateOptions;
-import org.jclouds.vcloud.VCloudApi;
-import org.jclouds.vcloud.compute.options.VCloudTemplateOptions;
-import org.jclouds.vcloud.domain.DiskAttachOrDetachParams;
-import org.jclouds.vcloud.domain.NetworkConnection;
-import org.jclouds.vcloud.domain.Task;
-import org.jclouds.vcloud.domain.Vm;
-import org.jclouds.vcloud.domain.network.IpAddressAllocationMode;
-import org.jclouds.vcloud.domain.network.OrgNetwork;
-import org.jclouds.vcloud.features.VAppApi;
-import org.jclouds.vcloud.features.VmApi;
-import org.wso2.carbon.utils.CarbonUtils;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Hashtable;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Set;
-
-
-public class VCloudIaas extends JcloudsIaas {
-
-
- private static final Log log = LogFactory.getLog(VCloudIaas.class);
-
- private static final String SHELL_TYPE = "shellType";
- private static final String SCRIPTS_PATH = "scripts";
- private static final String CUSTOMIZATION_SCRIPT = "customization";
- private static final String PAYLOAD = "PAYLOAD";
-
- public VCloudIaas(IaasProvider iaasProvider) {
- super(iaasProvider);
- }
-
- @Override
- public void buildComputeServiceAndTemplate() {
- // builds and sets Compute Service
- ComputeService computeService = ComputeServiceBuilderUtil.buildDefaultComputeService(getIaasProvider());
- getIaasProvider().setComputeService(computeService);
-
- // builds and sets Template
- buildTemplate();
-
- }
-
- public void buildTemplate() {
- IaasProvider iaasInfo = getIaasProvider();
-
- if (iaasInfo.getComputeService() == null) {
- String msg = "Compute service is null for IaaS provider: "
- + iaasInfo.getName();
- log.fatal(msg);
- throw new CloudControllerException(msg);
- }
-
- //get 'native' version of jclouds' vCloud API.
- ComputeServiceContext context = iaasInfo.getComputeService().getContext();
- VCloudApi api = context.unwrapApi(VCloudApi.class);
-
-
- TemplateBuilder templateBuilder = iaasInfo.getComputeService()
- .templateBuilder();
-
- // set image id specified
- templateBuilder.imageId(iaasInfo.getImage());
-
- // build the Template
- Template template = templateBuilder.build();
-
- // if you wish to auto assign IPs, instance spawning call should be
- // blocking, but if you
- // wish to assign IPs manually, it can be non-blocking.
- // is auto-assign-ip mode or manual-assign-ip mode? - default mode is
- // non-blocking
- boolean blockUntilRunning = Boolean.parseBoolean(iaasInfo
- .getProperty("autoAssignIp"));
- template.getOptions().as(TemplateOptions.class)
- .blockUntilRunning(blockUntilRunning);
-
- // this is required in order to avoid creation of additional security
- // groups by Jclouds.
- template.getOptions().as(TemplateOptions.class)
- .inboundPorts(22, 80, 8080, 443, 8243);
-
- if (iaasInfo.getNetworkInterfaces() != null) {
- Set<String> networksSet = new LinkedHashSet<String>(iaasInfo.getNetworkInterfaces().length);
- Hashtable<String, NetworkConnection> vcloudNetworkOptions = new Hashtable<String, NetworkConnection>(iaasInfo.getNetworkInterfaces().length);
-
- int i = 0;
- for (NetworkInterface ni : iaasInfo.getNetworkInterfaces()) {
-
- String networkUuid = ni.getNetworkUuid();
- String networkName = null;
- IpAddressAllocationMode ipAllocMode = IpAddressAllocationMode.NONE;
- if (ni.getFixedIp() != null && !ni.getFixedIp().equals("")) {
- ipAllocMode = IpAddressAllocationMode.MANUAL;
- } else {
- ipAllocMode = IpAddressAllocationMode.POOL;
- }
-
- //fetch network name.
- try {
- OrgNetwork orgNet = api.getNetworkApi().getNetwork(new URI(networkUuid));
- networkName = orgNet.getName();
- } catch (URISyntaxException e) {
- log.error("Network UUID '" + networkUuid + "' is not a URI/href.");
- }
- NetworkConnection nc = new NetworkConnection(networkName, i, ni.getFixedIp(), null, true,
- null, //TODO: support fixed Mac addrs.
- ipAllocMode);
- networksSet.add(networkUuid);
- vcloudNetworkOptions.put(networkUuid, nc);
-
- i++;
- }
- //new NetworkConnectionSection()
-
- //VmApi vmApi = api.getVmApi();
- //vmApi.updateNetworkConnectionOfVm();
-
- template.getOptions().networks(networksSet);
- template.getOptions().as(VCloudTemplateOptions.class).networkConnections(vcloudNetworkOptions);
- }
-
- //template.getOptions().as(VCloudTemplateOptions.class)
- // .ipAddressAllocationMode(IpAddressAllocationMode.POOL);
-
- // set Template
- iaasInfo.setTemplate(template);
- }
-
- @Override
- public void setDynamicPayload(byte[] payload) {
- // in vCloud case we need to run a script
- IaasProvider iaasProvider = getIaasProvider();
-
- if (iaasProvider.getTemplate() == null || payload == null) {
- if (log.isDebugEnabled()) {
- log.debug("Payload for vCloud not found");
- }
- return;
- }
-
- String shellType = iaasProvider.getProperty(SHELL_TYPE);
-
- if (shellType == null || shellType.isEmpty()) {
- if (log.isDebugEnabled()) {
- log.debug("Shell Type for vCloud Customization script not found from properties");
- }
- return;
- }
-
- if (log.isDebugEnabled()) {
- log.debug(String.format("Shell Type '%s' will be used for vCloud Customization script", shellType));
- }
-
- // Payload is a String value
- String payloadStr = new String(payload);
-
- if (log.isDebugEnabled()) {
- log.debug(String.format("Payload '%s' will be used for vCloud Customization script", payload));
- }
-
- Template template = iaasProvider.getTemplate();
-
- File scriptPath = new File(CarbonUtils.getCarbonConfigDirPath(), SCRIPTS_PATH);
-
- File customizationScriptFile = new File(new File(scriptPath, shellType), CUSTOMIZATION_SCRIPT);
-
- if (!customizationScriptFile.exists()) {
- if (log.isWarnEnabled()) {
- log.warn(String.format("The vCloud Customization script '%s' does not exist",
- customizationScriptFile.getAbsolutePath()));
- }
- return;
- }
-
- String customizationScript = null;
-
- try {
- customizationScript = FileUtils.readFileToString(customizationScriptFile);
- } catch (IOException e) {
- if (log.isErrorEnabled()) {
- log.error(
- String.format("Error reading the vCloud Customization script '%s'",
- customizationScriptFile.getAbsolutePath()), e);
- }
- }
-
- if (StringUtils.isEmpty(customizationScript)) {
- if (log.isDebugEnabled()) {
- log.debug("No content vCloud Customization script not found from properties");
- }
- return;
- }
-
- // Set payload
- customizationScript = customizationScript.replaceAll(PAYLOAD, payloadStr);
-
- if (log.isDebugEnabled()) {
- log.debug(String.format("The vCloud Customization script\n%s", customizationScript));
- }
-
- // Ensure the script is run.
- if (customizationScript.length() >= 49000) {
- log.warn("The vCloud customization script is >=49000 bytes in size; uploading dummy script and running real script via ssh.");
- String dummyCustomizationScript = "#!/bin/sh\n"
- + "#STRATOS: the real customization script will be invoked via ssh, since it exceeds the 49000 byte limit "
- + "imposed by vCloud;\n"
- + "#see "
- + "http://pubs.vmware.com/vcd-55/topic/com.vmware.vcloud.api.doc_55/GUID-1BA3B7C5-B46C-48F7-8704-945BC47A940D.html\n";
- template.getOptions().as(VCloudTemplateOptions.class).customizationScript(dummyCustomizationScript);
- template.getOptions().runScript(customizationScript);
- } else {
- template.getOptions().as(VCloudTemplateOptions.class).customizationScript(customizationScript);
- }
-
- // Run the script
- //template.getOptions().runScript(customizationScript);
- }
-
- @Override
- public boolean createKeyPairFromPublicKey(String region, String keyPairName, String publicKey) {
-
- // TODO
- return false;
- }
-
- @Override
- public List<String> associateAddresses(NodeMetadata node) {
-
- // TODO
- return null;
-
- }
-
- @Override
- public String associatePredefinedAddress(NodeMetadata node, String ip) {
- return "";
- }
-
- @Override
- public void releaseAddress(String ip) {
- // TODO
- }
-
- @Override
- public boolean isValidRegion(String region) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public boolean isValidZone(String region, String zone) {
- // TODO Auto-generated method stub
- return true;
- }
-
- @Override
- public boolean isValidHost(String zone, String host) {
- // TODO Auto-generated method stub
- return true;
- }
-
- @Override
- public PartitionValidator getPartitionValidator() {
- return new VCloudPartitionValidator();
- }
-
- @Override
- public String createVolume(int sizeGB, String snapshotId) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public String attachVolume(String instanceId, String volumeId, String deviceName) {
- IaasProvider iaasInfo = getIaasProvider();
-
- if (StringUtils.isEmpty(volumeId)) {
- log.error("Volume provided to attach can not be null");
- }
-
- if (StringUtils.isEmpty(instanceId)) {
- log.error("Instance provided to attach can not be null");
- }
-
- URI instanceIdHref = null;
- URI volumeIdHref = null;
- try {
- //the instanceId format is a bit silly for vCloud.
- instanceIdHref = new URI("https:/" + instanceId);
- } catch (URISyntaxException e) {
- log.error("Failed to attach volume, because the instance id cannot be converted into a url by concatenating "
- + "'https:/' with " + instanceId + ". Full stacktrace: " + e.toString());
- return null;
- }
- try {
- volumeIdHref = new URI(volumeId);
- } catch (URISyntaxException e) {
- log.error("Failed to attach voluume, because the volume id '" + volumeId + "' is not a valid href (URI))"
- + e.toString());
- }
-
- //get 'native' version of jclouds' vCloud API.
- ComputeServiceContext context = iaasInfo.getComputeService()
- .getContext();
-
- VCloudApi api = context.unwrapApi(VCloudApi.class);
-
- //Disks need to be attached to individual VMs, not vApps. The instanceId is the VApp.
- VAppApi vAppApi = api.getVAppApi();
- Set<Vm> vmsInVapp = vAppApi.getVApp(instanceIdHref).getChildren();
- //Each vApp today has just 1 VM in it. Validate assumption.
- assert (vmsInVapp.size() == 1);
- Vm vm = vmsInVapp.iterator().next();
- URI vmHref = vm.getHref();
- VmApi vmApi = api.getVmApi();
-
- // invest
- /*
- VCloudHardDisk.Builder hardDiskBuilder = new VCloudHardDisk.Builder();
- VCloudHardDisk hardDisk = hardDiskBuilder.instanceID(volumeId).build();
- VCloudVirtualHardwareSection vvhs = vm.getVirtualHardwareSection();
- VCloudHardDisk.Builder Vchd = new VCloudHardDisk.Builder();
- vvhs.toBuilder().item(Vchd.capacity(3).instanceID("hgfhgf").build()).build();
- VApp va = vAppApi.getVApp(instanceIdHref);
-
- */ //EO invest
- DiskAttachOrDetachParams params = new DiskAttachOrDetachParams(volumeIdHref);
- Task t = vmApi.attachDisk(vmHref, params);
-
- log.info(String.format("Volume [id]: %s attachment for instance [id]: %s was successful [status]: Attaching. Iaas : %s, Task: %s", volumeId, instanceId, iaasInfo, t));
- return "Attaching";
- }
-
- @Override
- public void detachVolume(String instanceId, String volumeId) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void deleteVolume(String volumeId) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public String getIaasDevice(String device) {
- return device;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/vcloud/VCloudPartitionValidator.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/vcloud/VCloudPartitionValidator.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/vcloud/VCloudPartitionValidator.java
deleted file mode 100644
index 5a19741..0000000
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/vcloud/VCloudPartitionValidator.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.stratos.cloud.controller.iaases.vcloud;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.cloud.controller.domain.IaasProvider;
-import org.apache.stratos.cloud.controller.domain.Partition;
-import org.apache.stratos.cloud.controller.exception.InvalidPartitionException;
-import org.apache.stratos.cloud.controller.iaases.Iaas;
-import org.apache.stratos.cloud.controller.iaases.PartitionValidator;
-
-import java.util.Properties;
-
-
-/**
- * The VCloud {@link org.apache.stratos.cloud.controller.iaases.PartitionValidator} implementation.
- */
-public class VCloudPartitionValidator implements PartitionValidator {
-
- @SuppressWarnings("unused")
- private static final Log log = LogFactory.getLog(VCloudPartitionValidator.class);
- private IaasProvider iaasProvider;
- @SuppressWarnings("unused")
- private Iaas iaas;
-
- @Override
- public IaasProvider validate(Partition partition, Properties properties) throws InvalidPartitionException {
- //TODO: implement real validation logic
- return iaasProvider;
-
- }
-
- @Override
- public void setIaasProvider(IaasProvider iaas) {
- this.iaasProvider = iaas;
- this.iaas = iaas.getIaas();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Scope.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Scope.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Scope.java
new file mode 100644
index 0000000..984494e
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Scope.java
@@ -0,0 +1,26 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.apache.stratos.cloud.controller.util;
+
+/**
+ * represents the scope of each partition which can be configured in stratos.
+ */
+public enum Scope {
+ PROVIDER, REGION, ZONE, HOST
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Scope.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Scope.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Scope.java
deleted file mode 100644
index 4c228b3..0000000
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Scope.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
-* Licensed to the Apache Software Foundation (ASF) under one
-* or more contributor license agreements. See the NOTICE file
-* distributed with this work for additional information
-* regarding copyright ownership. The ASF licenses this file
-* to you under the Apache License, Version 2.0 (the
-* "License"); you may not use this file except in compliance
-* with the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing,
-* software distributed under the License is distributed on an
-* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-* KIND, either express or implied. See the License for the
-* specific language governing permissions and limitations
-* under the License.
-*/
-package org.apache.stratos.messaging.domain.topology;
-
-/**
- * represents the scope of each partition which can be configured in stratos.
- */
-public enum Scope {
- provider, region, zone, host
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/README.txt
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/README.txt b/dependencies/jclouds/apis/gce/1.8.1-stratos/README.txt
deleted file mode 100644
index 0801104..0000000
--- a/dependencies/jclouds/apis/gce/1.8.1-stratos/README.txt
+++ /dev/null
@@ -1,77 +0,0 @@
-======
-Stratos GCE provider 1.8.1
-======
-
-This code in Stratos is copied from Jclouds GCE [1]
-The jclouds GCE code has 2 directories oauth & google-compute-engine
-In Stratos, these two directories are mered into one.
-
-[1] https://github.com/jclouds/jclouds-labs-google/tree/jclouds-labs-google-1.8.1
-
-
-
-
-======
-jclouds Google Compute Engine Provider
-======
-
-
-Authenticating into the instances:
---------
-
-User:
-If no user is provided in GoogleComputeEngineTemplateOptions when launching an instance by default "jclouds" is used.
-
-Credential:
-
-GCE uses exclusively ssh keys to login into instances.
-In order for an instance to be sshable a public key must be installed. Public keys are installed if they are present in the project or instance's metatada.
-
-For an instance to be ssable one of the following must happen:
-1 - the project's metadata has an adequately built "sshKeys" entry and a corresponding private key is provided in GoogleComputeEngineTemplateOptions when createNodesInGroup is called.
-2 - an instance of GoogleComputeEngineTemplateOptions with an adequate public and private key is provided.
-
-NOTE: if methods 2 is chosen the global project keys will not be installed in the instance.
-
-Please refer to Google's documentation on how to form valid project wide ssh keys metadata entries.
-
-FAQ:
---------
-
-* Q. What is the identity for GCE?
-
-A. the identity is the developer email which can be obtained from the admin GUI. Its usually something in the form: <my account id>@developer.gserviceaccount.com
-
-* Q. What is the credential for GCE
-
-A. the credential is a private key, in pem format. It can be extracted from the p12 keystore that is obtained when creating a "Service Account" (in the GUI: Google apis console > Api Access > Create another client ID > "Service Account"
-
-* Q. How to convert a p12 keystore into a pem format jclouds Google Compute Engine can handle:
-
-A.
-
-1. Convert the p12 file into pem format (it will ask for the keystore password, which is usually "notasecret"):
- openssl pkcs12 -in <my_keystore>.p12 -out <my_keystore>.pem -nodes
-
-2. Extract only the pk and remove passphrase
- openssl rsa -in <my_keystore>.pem -out <my_key>.pem
-
-The last file (<my_key>.pem) should contain the pk that needs to be passed to `ContextBuilder.credential()` for the provider `google-compute-engine`.
-
-
-Running the live tests:
---------
-
-1. Place the following in your ~/.m2/settings.xml in a profile enabled when live:
-```
- <test.google-compute-engine.identity>YOUR_ACCOUNT_NUMBER@developer.gserviceaccount.com</test.google-compute-engine.identity>
- <test.google-compute-engine.credential>-----BEGIN RSA PRIVATE KEY-----
-MIICXgIBAAKBgQRRbRqVDtJLN1MO/xJoKqZuphDeBh5jIKueW3aNIiWs1XFcct+h
--- this text is literally from your <my_key>.pem
-aH7xmpHSTbbXmQkuuv+z8EKijigprd/FoJpTX1f5/R+4wQ==
------END RSA PRIVATE KEY-----</test.google-compute-engine.credential>
- </properties>
-```
-
-2. mvn clean install -Plive
-
http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/pom.xml
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/pom.xml b/dependencies/jclouds/apis/gce/1.8.1-stratos/pom.xml
deleted file mode 100644
index c1a7b9d..0000000
--- a/dependencies/jclouds/apis/gce/1.8.1-stratos/pom.xml
+++ /dev/null
@@ -1,144 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.jclouds.labs</groupId>
- <artifactId>jclouds-labs-google</artifactId>
- <version>1.8.1</version>
- </parent>
-
- <!-- TODO: when out of labs, switch to org.jclouds.provider -->
- <groupId>org.apache.stratos</groupId>
- <artifactId>gce</artifactId>
- <version>1.8.1-stratosv1</version>
- <name>jclouds Google Compute Engine provider</name>
- <description>jclouds components to access GoogleCompute</description>
- <packaging>bundle</packaging>
-
- <properties>
- <jclouds.version>1.8.1</jclouds.version>
- <test.google-compute-engine.identity>Email associated with the Google API client_id
- </test.google-compute-engine.identity>
- <test.google-compute-engine.credential>Private key (PKCS12 file) associated with the Google API client_id
- </test.google-compute-engine.credential>
- <test.google-compute-engine.api-version>v1</test.google-compute-engine.api-version>
- <test.google-compute-engine.build-version/>
- <test.google-compute-engine.template>imageId=debian-7-wheezy-v20131120,locationId=us-central1-a,minRam=2048
- </test.google-compute-engine.template>
- <jclouds.osgi.export>org.jclouds.googlecomputeengine*;version="${project.version}"</jclouds.osgi.export>
- <jclouds.osgi.import>
- org.jclouds.compute.internal;version="${jclouds.version}",
- org.jclouds.rest.internal;version="${jclouds.version}",
- org.jclouds*;version="${jclouds.version}",
- *
- </jclouds.osgi.import>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.jclouds</groupId>
- <artifactId>jclouds-core</artifactId>
- <version>${jclouds.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.jclouds</groupId>
- <artifactId>jclouds-compute</artifactId>
- <version>${jclouds.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.jclouds</groupId>
- <artifactId>jclouds-compute</artifactId>
- <version>${jclouds.version}</version>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.jclouds</groupId>
- <artifactId>jclouds-core</artifactId>
- <version>${jclouds.version}</version>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.jclouds.driver</groupId>
- <artifactId>jclouds-slf4j</artifactId>
- <version>${jclouds.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.jclouds.driver</groupId>
- <artifactId>jclouds-sshj</artifactId>
- <version>${jclouds.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
- <profiles>
- <profile>
- <id>live</id>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <executions>
- <execution>
- <id>default-test</id>
- <configuration>
- <skipTests>true</skipTests>
- </configuration>
- </execution>
- <execution>
- <id>integration</id>
- <phase>integration-test</phase>
- <goals>
- <goal>test</goal>
- </goals>
- <configuration>
- <systemPropertyVariables>
- <test.google-compute-engine.identity>${test.google-compute-engine.identity}
- </test.google-compute-engine.identity>
- <test.google-compute-engine.credential>
- ${test.google-compute-engine.credential}
- </test.google-compute-engine.credential>
- <test.google-compute-engine.api-version>
- ${test.google-compute-engine.api-version}
- </test.google-compute-engine.api-version>
- <test.google-compute-engine.build-version>
- ${test.google-compute-engine.build-version}
- </test.google-compute-engine.build-version>
- <test.google-compute-engine.template>${test.google-compute-engine.template}
- </test.google-compute-engine.template>
- </systemPropertyVariables>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
-</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApi.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApi.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApi.java
deleted file mode 100644
index 6440d91..0000000
--- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApi.java
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.googlecomputeengine;
-
-import java.io.Closeable;
-
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-
-import org.jclouds.googlecomputeengine.features.AddressApi;
-import org.jclouds.googlecomputeengine.features.DiskApi;
-import org.jclouds.googlecomputeengine.features.FirewallApi;
-import org.jclouds.googlecomputeengine.features.GlobalOperationApi;
-import org.jclouds.googlecomputeengine.features.ImageApi;
-import org.jclouds.googlecomputeengine.features.InstanceApi;
-import org.jclouds.googlecomputeengine.features.MachineTypeApi;
-import org.jclouds.googlecomputeengine.features.NetworkApi;
-import org.jclouds.googlecomputeengine.features.ProjectApi;
-import org.jclouds.googlecomputeengine.features.RegionApi;
-import org.jclouds.googlecomputeengine.features.RegionOperationApi;
-import org.jclouds.googlecomputeengine.features.RouteApi;
-import org.jclouds.googlecomputeengine.features.SnapshotApi;
-import org.jclouds.googlecomputeengine.features.ZoneApi;
-import org.jclouds.googlecomputeengine.features.ZoneOperationApi;
-import org.jclouds.rest.annotations.Delegate;
-
-import com.google.common.annotations.Beta;
-
-
-/**
- * Provides access to GoogleCompute.
- * <p/>
- *
- * @see <a href="https://developers.google.com/compute/docs/reference/v1">api doc</a>
- */
-@Beta
-public interface GoogleComputeEngineApi extends Closeable {
-
- /**
- * Provides access to Address features
- *
- * @param projectName the name of the project
- */
- @Delegate
- @Path("/projects/{project}")
- AddressApi getAddressApiForProject(@PathParam("project") String projectName);
-
- /**
- * Provides access to Disk features
- *
- * @param projectName the name of the project
- */
- @Delegate
- @Path("/projects/{project}")
- DiskApi getDiskApiForProject(@PathParam("project") String projectName);
-
- /**
- * Provides access to Firewall features
- *
- * @param projectName the name of the project
- */
- @Delegate
- @Path("/projects/{project}")
- FirewallApi getFirewallApiForProject(@PathParam("project") String projectName);
-
- /**
- * Provides access to Global Operation features
- *
- * @param projectName the name of the project
- */
- @Delegate
- @Path("/projects/{project}")
- GlobalOperationApi getGlobalOperationApiForProject(@PathParam("project") String projectName);
-
- /**
- * Provides access to Image features
- *
- * @param projectName the name of the project
- */
- @Delegate
- @Path("/projects/{project}")
- ImageApi getImageApiForProject(@PathParam("project") String projectName);
-
- /**
- * Provides access to Instance features
- *
- * @param projectName the name of the project
- */
- @Delegate
- @Path("/projects/{project}")
- InstanceApi getInstanceApiForProject(@PathParam("project") String projectName);
-
- /**
- * Provides access to MachineType features
- *
- * @param projectName the name of the project
- */
- @Delegate
- @Path("/projects/{project}")
- MachineTypeApi getMachineTypeApiForProject(@PathParam("project") String projectName);
-
- /**
- * Provides access to Network features
- *
- * @param projectName the name of the project
- */
- @Delegate
- @Path("/projects/{project}")
- NetworkApi getNetworkApiForProject(@PathParam("project") String projectName);
-
- /**
- * Provides access to Project features
- */
- @Delegate
- ProjectApi getProjectApi();
-
- /**
- * Provides access to Region features
- *
- * @param projectName the name of the project
- */
- @Delegate
- @Path("/projects/{project}")
- RegionApi getRegionApiForProject(@PathParam("project") String projectName);
-
- /**
- * Provides access to Region Operation features
- *
- * @param projectName the name of the project
- */
- @Delegate
- @Path("/projects/{project}")
- RegionOperationApi getRegionOperationApiForProject(@PathParam("project") String projectName);
-
- /**
- * Provides access to Route features
- *
- * @param projectName the name of the project
- */
- @Delegate
- @Path("/projects/{project}")
- RouteApi getRouteApiForProject(@PathParam("project") String projectName);
-
- /**
- * Provides access to Snapshot features
- *
- * @param projectName the name of the project
- */
- @Delegate
- @Path("/projects/{project}")
- SnapshotApi getSnapshotApiForProject(@PathParam("project") String projectName);
-
- /**
- * Provides access to Zone features
- *
- * @param projectName the name of the project
- */
- @Delegate
- @Path("/projects/{project}")
- ZoneApi getZoneApiForProject(@PathParam("project") String projectName);
-
- /**
- * Provides access to Zone Operation features
- *
- * @param projectName the name of the project
- */
- @Delegate
- @Path("/projects/{project}")
- ZoneOperationApi getZoneOperationApiForProject(@PathParam("project") String projectName);
-
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApiMetadata.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApiMetadata.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApiMetadata.java
deleted file mode 100644
index 544a851..0000000
--- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApiMetadata.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.googlecomputeengine;
-
-import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
-import static org.jclouds.compute.config.ComputeServiceProperties.TEMPLATE;
-import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.GCE_PROVIDER_NAME;
-import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.OPERATION_COMPLETE_INTERVAL;
-import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.OPERATION_COMPLETE_TIMEOUT;
-import static org.jclouds.oauth.v2.config.OAuthProperties.AUDIENCE;
-import static org.jclouds.oauth.v2.config.OAuthProperties.SIGNATURE_OR_MAC_ALGORITHM;
-import static org.jclouds.reflect.Reflection2.typeToken;
-
-import java.net.URI;
-import java.util.Properties;
-
-import org.jclouds.compute.ComputeServiceContext;
-import org.jclouds.googlecomputeengine.compute.config.GoogleComputeEngineServiceContextModule;
-import org.jclouds.googlecomputeengine.config.GoogleComputeEngineHttpApiModule;
-import org.jclouds.googlecomputeengine.config.GoogleComputeEngineParserModule;
-import org.jclouds.googlecomputeengine.config.OAuthModuleWithoutTypeAdapters;
-import org.jclouds.oauth.v2.config.OAuthAuthenticationModule;
-import org.jclouds.rest.internal.BaseHttpApiMetadata;
-
-import com.google.common.collect.ImmutableSet;
-import com.google.inject.Module;
-
-/**
- * Implementation of {@link ApiMetadata} for GoogleCompute v1 API
- */
-public class GoogleComputeEngineApiMetadata extends BaseHttpApiMetadata<GoogleComputeEngineApi> {
-
- @Override
- public Builder toBuilder() {
- return new Builder().fromApiMetadata(this);
- }
-
- public GoogleComputeEngineApiMetadata() {
- this(new Builder());
- }
-
- protected GoogleComputeEngineApiMetadata(Builder builder) {
- super(builder);
- }
-
- public static Properties defaultProperties() {
- Properties properties = BaseHttpApiMetadata.defaultProperties();
- properties.put("oauth.endpoint", "https://accounts.google.com/o/oauth2/token");
- properties.put(AUDIENCE, "https://accounts.google.com/o/oauth2/token");
- properties.put(SIGNATURE_OR_MAC_ALGORITHM, "RS256");
- properties.put(PROPERTY_SESSION_INTERVAL, 3600);
- properties.setProperty(TEMPLATE, "osFamily=DEBIAN,osVersionMatches=7\\..*,locationId=us-central1-a,loginUser=jclouds");
- properties.put(OPERATION_COMPLETE_INTERVAL, 500);
- properties.put(OPERATION_COMPLETE_TIMEOUT, 600000);
- return properties;
- }
-
- public static class Builder extends BaseHttpApiMetadata.Builder<GoogleComputeEngineApi, Builder> {
-
- protected Builder() {
- id(GCE_PROVIDER_NAME)
- .name("Google Compute Engine Api")
- .identityName("Email associated with the Google API client_id")
- .credentialName("Private key literal associated with the Google API client_id")
- .documentation(URI.create("https://developers.google.com/compute/docs"))
- .version("v1")
- .defaultEndpoint("https://www.googleapis.com/compute/v1")
- .defaultProperties(GoogleComputeEngineApiMetadata.defaultProperties())
- .view(typeToken(ComputeServiceContext.class))
- .defaultModules(ImmutableSet.<Class<? extends Module>>builder()
- .add(GoogleComputeEngineHttpApiModule.class)
- .add(GoogleComputeEngineParserModule.class)
- .add(OAuthAuthenticationModule.class)
- .add(OAuthModuleWithoutTypeAdapters.class)
- .add(GoogleComputeEngineServiceContextModule.class)
- .build());
- }
-
- @Override
- public GoogleComputeEngineApiMetadata build() {
- return new GoogleComputeEngineApiMetadata(this);
- }
-
- @Override
- protected Builder self() {
- return this;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineConstants.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineConstants.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineConstants.java
deleted file mode 100644
index d20ff98..0000000
--- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineConstants.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.googlecomputeengine;
-
-import org.jclouds.domain.Location;
-import org.jclouds.domain.LocationBuilder;
-import org.jclouds.domain.LocationScope;
-
-import com.google.common.annotations.Beta;
-
-public final class GoogleComputeEngineConstants {
-
- public static final String GCE_PROVIDER_NAME = "google-compute-engine";
-
- /**
- * The name of the project that keeps public resources.
- */
- public static final String GOOGLE_PROJECT = "google";
-
- public static final String CENTOS_PROJECT = "centos-cloud";
-
- public static final String DEBIAN_PROJECT = "debian-cloud";
-
- public static final String COMPUTE_SCOPE = "https://www.googleapis.com/auth/compute";
-
- public static final String COMPUTE_READONLY_SCOPE = "https://www.googleapis.com/auth/compute.readonly";
-
- public static final String STORAGE_READONLY_SCOPE = "https://www.googleapis.com/auth/devstorage.read_only";
-
- public static final String STORAGE_WRITEONLY_SCOPE = "https://www.googleapis.com/auth/devstorage.write_only";
-
-
- /**
- * The total time, in msecs, to wait for an operation to complete.
- */
- @Beta
- public static final String OPERATION_COMPLETE_TIMEOUT = "jclouds.google-compute-engine.operation-complete-timeout";
-
- /**
- * The interval, in msecs, between calls to check whether an operation has completed.
- */
- @Beta
- public static final String OPERATION_COMPLETE_INTERVAL = "jclouds.google-compute-engine.operation-complete-interval";
-
- public static final Location GOOGLE_PROVIDER_LOCATION = new LocationBuilder().scope(LocationScope.PROVIDER).id
- (GCE_PROVIDER_NAME).description(GCE_PROVIDER_NAME).build();
-
-
- /**
- * The key we look for in instance metadata for the URI for the image the instance was created from.
- */
- public static final String GCE_IMAGE_METADATA_KEY = "jclouds-image";
-
- /**
- * Metadata key to check for whether we should delete an instance's boot disk when we delete the instance.
- */
- public static final String GCE_DELETE_BOOT_DISK_METADATA_KEY = "jclouds-delete-boot-disk";
-
- /**
- * The suffix we append to auto-created boot disk names.
- */
- public static final String GCE_BOOT_DISK_SUFFIX = "boot-disk";
-
- private GoogleComputeEngineConstants() {
- throw new AssertionError("intentionally unimplemented");
- }
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineService.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineService.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineService.java
deleted file mode 100644
index 3c140eb..0000000
--- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineService.java
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.googlecomputeengine.compute;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static java.util.concurrent.TimeUnit.MILLISECONDS;
-import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING;
-import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_SUSPENDED;
-import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_TERMINATED;
-import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.OPERATION_COMPLETE_INTERVAL;
-import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.OPERATION_COMPLETE_TIMEOUT;
-import static org.jclouds.util.Predicates2.retry;
-
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.atomic.AtomicReference;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.inject.Provider;
-
-import org.jclouds.Constants;
-import org.jclouds.collect.Memoized;
-import org.jclouds.compute.ComputeServiceContext;
-import org.jclouds.compute.callables.RunScriptOnNode;
-import org.jclouds.compute.domain.Hardware;
-import org.jclouds.compute.domain.Image;
-import org.jclouds.compute.domain.NodeMetadata;
-import org.jclouds.compute.domain.TemplateBuilder;
-import org.jclouds.compute.extensions.ImageExtension;
-import org.jclouds.compute.extensions.SecurityGroupExtension;
-import org.jclouds.compute.functions.GroupNamingConvention;
-import org.jclouds.compute.internal.BaseComputeService;
-import org.jclouds.compute.internal.PersistNodeCredentials;
-import org.jclouds.compute.options.TemplateOptions;
-import org.jclouds.compute.reference.ComputeServiceConstants;
-import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
-import org.jclouds.compute.strategy.DestroyNodeStrategy;
-import org.jclouds.compute.strategy.GetImageStrategy;
-import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
-import org.jclouds.compute.strategy.InitializeRunScriptOnNodeOrPlaceInBadMap;
-import org.jclouds.compute.strategy.ListNodesStrategy;
-import org.jclouds.compute.strategy.RebootNodeStrategy;
-import org.jclouds.compute.strategy.ResumeNodeStrategy;
-import org.jclouds.compute.strategy.SuspendNodeStrategy;
-import org.jclouds.domain.Credentials;
-import org.jclouds.domain.Location;
-import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
-import org.jclouds.googlecomputeengine.compute.options.GoogleComputeEngineTemplateOptions;
-import org.jclouds.googlecomputeengine.config.UserProject;
-import org.jclouds.googlecomputeengine.domain.Firewall;
-import org.jclouds.googlecomputeengine.domain.Network;
-import org.jclouds.googlecomputeengine.domain.Operation;
-import org.jclouds.googlecomputeengine.features.FirewallApi;
-import org.jclouds.http.HttpResponse;
-import org.jclouds.scriptbuilder.functions.InitAdminAccess;
-
-import com.google.common.base.Function;
-import com.google.common.base.Optional;
-import com.google.common.base.Predicate;
-import com.google.common.base.Supplier;
-import com.google.common.collect.Sets;
-import com.google.common.util.concurrent.Atomics;
-import com.google.common.util.concurrent.ListeningExecutorService;
-
-public class GoogleComputeEngineService extends BaseComputeService {
-
- private final Function<Set<? extends NodeMetadata>, Set<String>> findOrphanedGroups;
- private final GroupNamingConvention.Factory namingConvention;
- private final GoogleComputeEngineApi api;
- private final Supplier<String> project;
- private final Predicate<AtomicReference<Operation>> operationDonePredicate;
- private final long operationCompleteCheckInterval;
- private final long operationCompleteCheckTimeout;
-
- @Inject
- protected GoogleComputeEngineService(ComputeServiceContext context,
- Map<String, Credentials> credentialStore,
- @Memoized Supplier<Set<? extends Image>> images,
- @Memoized Supplier<Set<? extends Hardware>> hardwareProfiles,
- @Memoized Supplier<Set<? extends Location>> locations,
- ListNodesStrategy listNodesStrategy,
- GetImageStrategy getImageStrategy,
- GetNodeMetadataStrategy getNodeMetadataStrategy,
- CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy,
- RebootNodeStrategy rebootNodeStrategy,
- DestroyNodeStrategy destroyNodeStrategy,
- ResumeNodeStrategy resumeNodeStrategy,
- SuspendNodeStrategy suspendNodeStrategy,
- Provider<TemplateBuilder> templateBuilderProvider,
- @Named("DEFAULT") Provider<TemplateOptions> templateOptionsProvider,
- @Named(TIMEOUT_NODE_RUNNING) Predicate<AtomicReference<NodeMetadata>>
- nodeRunning,
- @Named(TIMEOUT_NODE_TERMINATED) Predicate<AtomicReference<NodeMetadata>>
- nodeTerminated,
- @Named(TIMEOUT_NODE_SUSPENDED)
- Predicate<AtomicReference<NodeMetadata>> nodeSuspended,
- InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory,
- InitAdminAccess initAdminAccess,
- RunScriptOnNode.Factory runScriptOnNodeFactory,
- PersistNodeCredentials persistNodeCredentials,
- ComputeServiceConstants.Timeouts timeouts,
- @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
- Optional<ImageExtension> imageExtension,
- Optional<SecurityGroupExtension> securityGroupExtension,
- Function<Set<? extends NodeMetadata>, Set<String>> findOrphanedGroups,
- GroupNamingConvention.Factory namingConvention,
- GoogleComputeEngineApi api,
- @UserProject Supplier<String> project,
- @Named("global") Predicate<AtomicReference<Operation>> operationDonePredicate,
- @Named(OPERATION_COMPLETE_INTERVAL) Long operationCompleteCheckInterval,
- @Named(OPERATION_COMPLETE_TIMEOUT) Long operationCompleteCheckTimeout) {
-
- super(context, credentialStore, images, hardwareProfiles, locations, listNodesStrategy, getImageStrategy,
- getNodeMetadataStrategy, runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy,
- resumeNodeStrategy, suspendNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning,
- nodeTerminated, nodeSuspended, initScriptRunnerFactory, initAdminAccess, runScriptOnNodeFactory,
- persistNodeCredentials, timeouts, userExecutor, imageExtension, securityGroupExtension);
- this.findOrphanedGroups = checkNotNull(findOrphanedGroups, "find orphaned groups function");
- this.namingConvention = checkNotNull(namingConvention, "naming convention factory");
- this.api = checkNotNull(api, "google compute api");
- this.project = checkNotNull(project, "user project name");
- this.operationDonePredicate = checkNotNull(operationDonePredicate, "operation completed predicate");
- this.operationCompleteCheckInterval = checkNotNull(operationCompleteCheckInterval,
- "operation completed check interval");
- this.operationCompleteCheckTimeout = checkNotNull(operationCompleteCheckTimeout,
- "operation completed check timeout");
- }
-
- @Override
- protected synchronized void cleanUpIncidentalResourcesOfDeadNodes(Set<? extends NodeMetadata> deadNodes) {
- Set<String> orphanedGroups = findOrphanedGroups.apply(deadNodes);
- for (String orphanedGroup : orphanedGroups) {
- cleanUpNetworksAndFirewallsForGroup(orphanedGroup);
- }
- }
-
-
- protected void cleanUpNetworksAndFirewallsForGroup(final String groupName) {
- String resourceName = namingConvention.create().sharedNameForGroup(groupName);
- final Network network = api.getNetworkApiForProject(project.get()).get(resourceName);
- FirewallApi firewallApi = api.getFirewallApiForProject(project.get());
- Predicate<Firewall> firewallBelongsToNetwork = new Predicate<Firewall>() {
- @Override
- public boolean apply(Firewall input) {
- return input != null && input.getNetwork().equals(network.getSelfLink());
- }
- };
-
- Set<AtomicReference<Operation>> operations = Sets.newHashSet();
- for (Firewall firewall : firewallApi.list().concat().filter(firewallBelongsToNetwork)) {
- operations.add(new AtomicReference<Operation>(firewallApi.delete(firewall.getName())));
- }
-
- for (AtomicReference<Operation> operation : operations) {
- retry(operationDonePredicate, operationCompleteCheckTimeout, operationCompleteCheckInterval,
- MILLISECONDS).apply(operation);
-
- if (operation.get().getHttpError().isPresent()) {
- HttpResponse response = operation.get().getHttpError().get();
- logger.warn("delete orphaned firewall %s failed. Http Error Code: %d HttpError: %s",
- operation.get().getTargetId(), response.getStatusCode(), response.getMessage());
- }
- }
-
- AtomicReference<Operation> operation = Atomics.newReference(api.getNetworkApiForProject(project.get()).delete(resourceName));
-
- retry(operationDonePredicate, operationCompleteCheckTimeout, operationCompleteCheckInterval,
- MILLISECONDS).apply(operation);
-
- if (operation.get().getHttpError().isPresent()) {
- HttpResponse response = operation.get().getHttpError().get();
- logger.warn("delete orphaned network failed. Http Error Code: " + response.getStatusCode() +
- " HttpError: " + response.getMessage());
- }
- }
-
-
- /**
- * returns template options, except of type {@link org.jclouds.googlecomputeengine.compute.options.GoogleComputeEngineTemplateOptions}.
- */
- @Override
- public GoogleComputeEngineTemplateOptions templateOptions() {
- return GoogleComputeEngineTemplateOptions.class.cast(super.templateOptions());
- }
-}