Skip to content

remove unsupported ci structure #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from
18 changes: 13 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<dependency>
<groupId>org.dasein</groupId>
<artifactId>dasein-cloud-core</artifactId>
<version>0.9.0</version>
<version>0.9.5-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.dasein</groupId>
Expand Down Expand Up @@ -149,19 +149,27 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
<version>1.19</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
<version>1.19</version>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
<scope>test</scope>
</dependency>


</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package org.dasein.cloud.ci;

import javax.annotation.Nonnull;
import org.dasein.cloud.CloudException;
import org.dasein.cloud.InternalException;
import org.dasein.cloud.google.Google;
import org.dasein.cloud.util.NamingConstraints;

import javax.annotation.Nonnull;
import java.util.Locale;

public class GCETopologyCapabilities implements TopologyCapabilities {

public GCETopologyCapabilities(Google provider) {
Expand All @@ -22,4 +24,9 @@ public GCETopologyCapabilities(Google provider) {
.constrainedBy('-');
}

@Override
public String getProviderTermForTopology(Locale locale) {
return "Instance Template";
}

}
27 changes: 8 additions & 19 deletions src/main/java/org/dasein/cloud/ci/GoogleCIServices.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package org.dasein.cloud.ci;

import javax.annotation.Nullable;

import org.dasein.cloud.google.Google;
import org.dasein.cloud.google.compute.server.ReplicapoolSupport;
import org.dasein.cloud.google.network.CIHttpLoadBalancerSupport;

public class GoogleCIServices extends AbstractCIServices<Google> {
import javax.annotation.Nullable;

public class GoogleCIServices extends AbstractConvergedInfrastructureServices<Google> {

public GoogleCIServices(Google provider) {
super(provider);
Expand All @@ -17,28 +15,19 @@ public GoogleCIServices(Google provider) {
return new ReplicapoolSupport(getProvider());
}

@Override
public @Nullable TopologySupport getTopologySupport() {
return new GoogleTopologySupport(getProvider());
}

@Override
public boolean hasConvergedInfrastructureSupport() {
return (getConvergedInfrastructureSupport() == null);
return (getConvergedInfrastructureSupport() != null);
}

@Override
public boolean hasTopologySupport() {
return (getTopologySupport() == null);
}

@Override
public ConvergedHttpLoadBalancerSupport getConvergedHttpLoadBalancerSupport() {
return new CIHttpLoadBalancerSupport(getProvider());
public @Nullable TopologySupport getTopologySupport() {
return new GoogleTopologySupport(getProvider());
}

@Override
public boolean hasConvergedHttpLoadBalancerSupport() {
return (getConvergedHttpLoadBalancerSupport() != null);
public boolean hasTopologySupport() {
return (getTopologySupport() != null);
}
}
195 changes: 2 additions & 193 deletions src/main/java/org/dasein/cloud/ci/GoogleTopologySupport.java
Original file line number Diff line number Diff line change
@@ -1,43 +1,18 @@
package org.dasein.cloud.ci;

import com.google.api.client.googleapis.json.GoogleJsonResponseException;
import com.google.api.services.compute.Compute.InstanceTemplates;
import com.google.api.services.compute.model.AccessConfig;
import com.google.api.services.compute.model.AttachedDisk;
import com.google.api.services.compute.model.AttachedDiskInitializeParams;
import com.google.api.services.compute.model.InstanceProperties;
import com.google.api.services.compute.model.InstanceTemplate;
import com.google.api.services.compute.model.InstanceTemplateList;
import com.google.api.services.compute.model.Metadata;
import com.google.api.services.compute.model.Metadata.Items;
import com.google.api.services.compute.model.NetworkInterface;
import com.google.api.services.compute.model.Operation;
import com.google.api.services.compute.model.Scheduling;
import com.google.api.services.compute.model.Tags;
import org.apache.log4j.Logger;
import org.dasein.cloud.CloudErrorType;
import org.dasein.cloud.CloudException;
import org.dasein.cloud.GeneralCloudException;
import org.dasein.cloud.InternalException;
import org.dasein.cloud.ci.Topology.VLANDevice;
import org.dasein.cloud.ci.Topology.VMDevice;
import org.dasein.cloud.ci.TopologyProvisionOptions.Disk;
import org.dasein.cloud.ci.TopologyProvisionOptions.Network;
import org.dasein.cloud.compute.Architecture;
import org.dasein.cloud.compute.MachineImage;
import org.dasein.cloud.compute.VirtualMachineProduct;
import org.dasein.cloud.google.Google;
import org.dasein.cloud.google.GoogleException;
import org.dasein.cloud.google.GoogleMethod;
import org.dasein.cloud.google.GoogleOperationType;
import org.dasein.cloud.google.compute.server.ServerSupport;

import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;

public class GoogleTopologySupport extends AbstractTopologySupport<Google> {
static private final Logger logger = Google.getLogger(GoogleTopologySupport.class);
Expand All @@ -55,11 +30,6 @@ public GoogleTopologySupport(Google provider) {
}
}

@Override
public String getProviderTermForTopology(Locale locale) {
return "Instance Template";
}

@Override
public boolean isSubscribed() throws CloudException, InternalException {
return true;
Expand All @@ -72,181 +42,20 @@ public Iterable<Topology> listTopologies(TopologyFilterOptions options) throws C
InstanceTemplateList templateList = instanceTemplates.list(getContext().getAccountNumber()).execute();
if (templateList != null && templateList.getItems() != null) {
for (InstanceTemplate template : templateList.getItems()) {
InstanceProperties templateProperties = template.getProperties();
VMDevice vmDevices = null;
String machineType = templateProperties.getMachineType();
ServerSupport server = new ServerSupport(getProvider());
Iterable<VirtualMachineProduct> vmProducts = server.listProducts(Architecture.I64, "us-central1-f");
for (VirtualMachineProduct vmProduct : vmProducts) {
if ( vmProduct.getName().equals(machineType) ) {
vmDevices = VMDevice.getInstance(machineType, machineType, vmProduct.getCpuCount(), vmProduct.getRamSize(), (String) null);
}
}

List<NetworkInterface> networkInterfaces = templateProperties.getNetworkInterfaces();
String name = null;
String deviceId = null;
for (NetworkInterface networkInterface : networkInterfaces) {
deviceId = networkInterface.getNetwork();
name = deviceId.replaceAll(".*/", "");
}

Topology topology = Topology.getInstance(getContext().getAccountNumber(), null, template.getName(), TopologyState.ACTIVE, template.getName(), template.getDescription());

if ( null != vmDevices ) {
topology = topology.withVirtualMachines(vmDevices);
}

if ( (null != name) && (null != deviceId) ) {
topology = topology.withVLANs(VLANDevice.getInstance(deviceId, name));
}
Topology topology = Topology.getInstance(getContext().getAccountNumber(), null, template.getName(), template.getName(), template.getDescription());

if ( (null == options) || (options.matches(topology)) ) {
topologies.add(topology);
}
}
}
} catch ( IOException e ) {
throw new GeneralCloudException("Problem listing topologies", e, CloudErrorType.GENERAL);
throw new GeneralCloudException("Problem listing topologies", e);
}

return topologies;
}

@Override
public boolean createTopology(@Nonnull TopologyProvisionOptions withTopologyOptions) throws CloudException, InternalException {
InstanceTemplate newInstanceTemplate = new InstanceTemplate();

newInstanceTemplate.setName(getCapabilities().getTopologyNamingConstraints().convertToValidName(withTopologyOptions.getProductName(), Locale.US));
newInstanceTemplate.setDescription(withTopologyOptions.getProductDescription());
InstanceProperties instanceProperties = new InstanceProperties();
instanceProperties.setCanIpForward(withTopologyOptions.getCanIpForward());
instanceProperties.setDescription(withTopologyOptions.getProductDescription());

VirtualMachineProduct p = getProvider().getComputeServices().getVirtualMachineSupport().getProduct(withTopologyOptions.getMachineType());
instanceProperties.setMachineType(p.getName());

List<Disk> disks = withTopologyOptions.getDiskArray();
List<AttachedDisk> attachedDisks = new ArrayList<AttachedDisk>();
for (Disk topologyDisk : disks) {
AttachedDisk disk = new AttachedDisk();
disk.setAutoDelete(topologyDisk.getAutoDelete());
disk.setBoot(topologyDisk.getBootable());
disk.setDeviceName(withTopologyOptions.getProductName());
AttachedDiskInitializeParams attachedDiskInitializeParams = new AttachedDiskInitializeParams();
MachineImage img = getProvider().getComputeServices().getImageSupport().getImage(topologyDisk.getDeviceSource());
attachedDiskInitializeParams.setSourceImage(img.getTag("contentLink").toString());
if (topologyDisk.getDeviceType() == TopologyProvisionOptions.DiskType.SSD_PERSISTENT_DISK) {
attachedDiskInitializeParams.setDiskType("pd-ssd");
} else {
attachedDiskInitializeParams.setDiskType("pd-standard");
}

disk.setInitializeParams(attachedDiskInitializeParams);
attachedDisks.add(disk);
}
instanceProperties.setDisks(attachedDisks); //must provide at least one AttachedDisk definition.

List<Network> topologyNetworksList = withTopologyOptions.getNetworkArray();
List<NetworkInterface> networks = new ArrayList<NetworkInterface>();
for (Network topologyNetwork : topologyNetworksList) {
NetworkInterface networkInterface = new NetworkInterface();
networkInterface.setName(topologyNetwork.getNetworkName());

List<TopologyProvisionOptions.AccessConfig> topologyNetworksAccessConfig = topologyNetwork.getAccessConfig();
List<AccessConfig> accessConfig = new ArrayList<AccessConfig>();

for (TopologyProvisionOptions.AccessConfig topologyAccessConfig : topologyNetworksAccessConfig) {
AccessConfig cfg = new AccessConfig();
cfg.setName(topologyAccessConfig.getName());
cfg.setKind("compute#accessConfig");
cfg.setType(topologyAccessConfig.getType());
accessConfig.add(cfg);
}
networkInterface.setAccessConfigs(accessConfig);
networks.add(networkInterface);
}
instanceProperties.setNetworkInterfaces(networks);

Tags tags = new Tags();
tags.setItems(withTopologyOptions.getTags());
instanceProperties.setTags(tags);

String[] sshKeys = withTopologyOptions.getSshKeys();
Metadata metadata = new Metadata();
List<Items> metadataItems = new ArrayList<Items>();
for (String sshKey : sshKeys) {
Metadata.Items item = new Metadata.Items() ;
item.setKey("sshKeys");
item.setValue(sshKey);
metadataItems.add(item);
}

Map<String, String> metaDataItems = withTopologyOptions.getMetadata();
for (String itemKey : metaDataItems.keySet()) {
Metadata.Items item = new Metadata.Items() ;
item.setKey(itemKey);
item.setValue(metaDataItems.get(itemKey));
metadataItems.add(item);
}

metadata.setItems(metadataItems);
instanceProperties.setMetadata(metadata);

Scheduling scheduling = new Scheduling();
scheduling.setAutomaticRestart(withTopologyOptions.getAutomaticRestart());
if (withTopologyOptions.getMaintenenceAction() == TopologyProvisionOptions.MaintenanceOption.MIGRATE_VM_INSTANCE) {
scheduling.setOnHostMaintenance("MIGRATE");
} else {
scheduling.setOnHostMaintenance("TERMINATE");
}
instanceProperties.setScheduling(scheduling);

/*
List<ServiceAccount> serviceAccounts = new ArrayList<ServiceAccount>();
ServiceAccount serviceAccount = new ServiceAccount();
serviceAccount.setEmail("email");
List<String> scopes = new ArrayList<String>();
serviceAccount.setScopes(scopes);
serviceAccounts.add(serviceAccount);
instanceProperties.setServiceAccounts(serviceAccounts);

*/
newInstanceTemplate.setProperties(instanceProperties);
try {
Operation job = instanceTemplates.insert(getContext().getAccountNumber(), newInstanceTemplate).execute();
GoogleMethod method = new GoogleMethod(getProvider());
method.getOperationComplete(getContext(), job, GoogleOperationType.GLOBAL_OPERATION, "", "");
} catch (IOException ex) {
if (ex.getClass() == GoogleJsonResponseException.class) {
GoogleJsonResponseException gjre = (GoogleJsonResponseException)ex;
throw new GoogleException(CloudErrorType.GENERAL, gjre.getStatusCode(), gjre.getContent(), gjre.getDetails().getMessage());
} else {
throw new GeneralCloudException(ex.getMessage(), ex, CloudErrorType.GENERAL);
}
}
return true;
}

@Override
public boolean removeTopologies(@Nonnull String[] topologyIds) throws CloudException, InternalException {
for (String topologyName: topologyIds) {
try {
Operation job = instanceTemplates.delete(getContext().getAccountNumber(), topologyName).execute();
GoogleMethod method = new GoogleMethod(getProvider());
method.getOperationComplete(getContext(), job, GoogleOperationType.GLOBAL_OPERATION, "", "");
} catch (IOException ex) {
if (ex.getClass() == GoogleJsonResponseException.class) {
GoogleJsonResponseException gjre = (GoogleJsonResponseException)ex;
throw new GoogleException(CloudErrorType.GENERAL, gjre.getStatusCode(), gjre.getContent(), gjre.getDetails().getMessage());
} else {
throw new GeneralCloudException(ex.getMessage(), ex, CloudErrorType.GENERAL);
}
}
}
return true;
}

private transient volatile GCETopologyCapabilities capabilities;

@Override
Expand Down
Loading