Search in sources :

Example 96 with OpsException

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);
    }
}
Also used : OpsException(org.platformlayer.ops.OpsException) Operation(com.google.api.services.compute.model.Operation) IOException(java.io.IOException)

Example 97 with OpsException

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);
    }
}
Also used : OpsException(org.platformlayer.ops.OpsException) Operation(com.google.api.services.compute.model.Operation) IOException(java.io.IOException) TimeoutException(java.util.concurrent.TimeoutException)

Example 98 with OpsException

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);
}
Also used : OpsException(org.platformlayer.ops.OpsException) PrivateKey(java.security.PrivateKey) Compute(com.google.api.services.compute.Compute) KeyParser(org.platformlayer.crypto.KeyParser) GoogleCredential(com.google.api.client.googleapis.auth.oauth2.GoogleCredential)

Example 99 with OpsException

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);
    }
}
Also used : SshKey(org.platformlayer.ops.helpers.SshKey) OpsTarget(org.platformlayer.ops.OpsTarget) OpsException(org.platformlayer.ops.OpsException) GitServer(org.platformlayer.service.gitosis.model.GitServer) OpenstackComputeMachine(org.platformlayer.ops.OpenstackComputeMachine)

Example 100 with OpsException

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);
    }
}
Also used : GraphiteService(org.platformlayer.service.graphite.model.GraphiteService) OpsException(org.platformlayer.ops.OpsException) DiskImageRecipe(org.platformlayer.service.imagefactory.v1.DiskImageRecipe) PersistentInstance(org.platformlayer.service.instancesupervisor.v1.PersistentInstance) OpenstackClientException(org.platformlayer.OpenstackClientException)

Aggregations

OpsException (org.platformlayer.ops.OpsException)142 IOException (java.io.IOException)39 File (java.io.File)19 ItemBase (org.platformlayer.core.model.ItemBase)19 RepositoryException (org.platformlayer.RepositoryException)18 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)17 Handler (org.platformlayer.ops.Handler)17 Tag (org.platformlayer.core.model.Tag)16 Command (org.platformlayer.ops.Command)16 Machine (org.platformlayer.ops.Machine)13 TagChanges (org.platformlayer.core.model.TagChanges)11 OpsTarget (org.platformlayer.ops.OpsTarget)11 TimeoutException (java.util.concurrent.TimeoutException)10 OpenstackException (org.openstack.client.OpenstackException)10 OpsContext (org.platformlayer.ops.OpsContext)10 X509Certificate (java.security.cert.X509Certificate)9 InetAddress (java.net.InetAddress)8 ProjectId (org.platformlayer.ids.ProjectId)8 ProcessExecution (org.platformlayer.ops.process.ProcessExecution)8 List (java.util.List)7