use of org.platformlayer.ops.OpsException in project platformlayer by platformlayer.
the class GoogleComputeClient method terminateInstance.
public Operation terminateInstance(String instanceId) throws OpsException {
try {
log.debug("Terminating instance: " + instanceId);
Operation operation = compute.instances().delete(projectId, instanceId).execute();
return operation;
} catch (IOException e) {
throw new OpsException("Error deleting instance", e);
}
}
use of org.platformlayer.ops.OpsException in project platformlayer by platformlayer.
the class GoogleComputeClient method createFirewallRule.
public void createFirewallRule(Firewall rule) throws OpsException {
try {
log.debug("Inserting firewall rule: " + rule);
Operation operation = compute.firewalls().insert(projectId, rule).execute();
waitComplete(operation, 5, TimeUnit.MINUTES);
// TODO: Check success of operation?
} catch (IOException e) {
throw new OpsException("Error creating firewall", e);
} catch (TimeoutException e) {
throw new OpsException("Timeout while waiting for firewall creation", e);
}
}
use of org.platformlayer.ops.OpsException in project platformlayer by platformlayer.
the class GoogleComputeClientFactory method getComputeClient.
public GoogleComputeClient getComputeClient(GoogleCloud cloud) throws OpsException {
KeyParser parser = new KeyParser();
Object parsed = parser.parse(cloud.serviceAccountKey.plaintext());
PrivateKey privateKey;
if (parsed == null) {
throw new OpsException("Cannot parse private key");
} else if (parsed instanceof PrivateKey) {
privateKey = (PrivateKey) parsed;
} else {
throw new OpsException("Expected private key, found: " + parsed.getClass().getSimpleName());
}
// Build service account credential.
GoogleCredential credential = new GoogleCredential.Builder().setTransport(HTTP_TRANSPORT).setJsonFactory(JSON_FACTORY).setServiceAccountId(cloud.serviceAccountId).setServiceAccountScopes(ComputeScopes.COMPUTE).setServiceAccountPrivateKey(privateKey).build();
Compute compute = new Compute(HTTP_TRANSPORT, JSON_FACTORY, credential);
return new GoogleComputeClient(platformLayerClient, compute, cloud.projectId);
}
use of org.platformlayer.ops.OpsException in project platformlayer by platformlayer.
the class GitHelpers method doForAllServers.
public void doForAllServers(GitosisOperation operation) throws Exception {
boolean failed = false;
for (Managed<GitServer> gitServer : platformLayer.listItems(GitServer.class)) {
if (gitServer.getState() != ManagedItemState.ACTIVE) {
log.warn("Server not yet active: " + gitServer);
failed = true;
continue;
}
OpenstackComputeMachine machine = instances.findMachine(gitServer);
if (machine == null) {
log.warn("Server instance not found: " + gitServer);
failed = true;
continue;
}
SshKey sshKey = service.getSshKey();
OpsTarget rootTarget = machine.getTarget(sshKey);
OpsTarget adminTarget = getAdminTarget(rootTarget, machine);
doOperation(adminTarget, operation);
}
if (failed) {
throw new OpsException("Could not update all DNS servers in cluster").setRetry(TimeSpan.ONE_MINUTE);
}
}
use of org.platformlayer.ops.OpsException in project platformlayer by platformlayer.
the class GraphiteServiceController method doOperation.
public void doOperation(Managed<GraphiteService> managed) throws OpsException {
DiskImageRecipe recipe = imageFactory.loadDiskImageResource(getClass(), "DiskImageRecipe.xml");
String imageId = imageFactory.getOrCreateImage(recipe);
GraphiteService model = (GraphiteService) managed.getModel();
PersistentInstance persistentInstance = new PersistentInstance();
persistentInstance.setImageId(imageId);
persistentInstance.setDnsName(model.dnsName);
try {
platformLayer.create(persistentInstance);
} catch (OpenstackClientException e) {
throw new OpsException("Error registering persistent instance", e);
}
}
Aggregations