Search in sources :

Example 71 with OpsException

use of org.platformlayer.ops.OpsException in project platformlayer by platformlayer.

the class ForEach method doRecursion.

public void doRecursion(Object controller, SshKey sshKey, Class<? extends ItemBase> machineItemClass, Class<? extends ItemBase> dataItemClass) throws OpsException {
    boolean failed = false;
    OpsContext ops = OpsContext.get();
    List<ItemBase> dataItems = Lists.newArrayList();
    ItemBase contextDataItem = ops.getInstance(dataItemClass);
    if (contextDataItem != null) {
        dataItems.add(contextDataItem);
    } else {
        for (ItemBase dataItem : platformLayer.listItems(dataItemClass)) {
            dataItems.add(dataItem);
        }
    }
    Object contextMachine = ops.getInstance(machineItemClass);
    if (contextMachine != null) {
        // We are presumably building the machine item
        PlatformLayerKey targetItemKey = ops.getJobRecord().getTargetItemKey();
        ItemBase machineItem = (ItemBase) contextMachine;
        if (!Objects.equal(targetItemKey, machineItem.getKey())) {
            throw new OpsException("Expected to find same model");
        }
        Machine machine = instances.findMachine(machineItem);
        if (machine == null) {
            log.warn("Server instance not found: " + contextMachine);
            failed = true;
        } else {
            OpsTarget target = machine.getTarget(sshKey);
            failed |= processDataItems(controller, dataItems, machineItem, machine, target);
        }
    } else {
        // We are building a data item
        for (ItemBase machineItem : platformLayer.listItems(machineItemClass)) {
            if (machineItem.getState() != ManagedItemState.ACTIVE) {
                log.warn("Machine not yet active: " + machineItem);
                failed = true;
                continue;
            }
            Machine machine = instances.findMachine(machineItem);
            if (machine == null) {
                log.warn("Server instance not found: " + machineItem);
                failed = true;
                continue;
            }
            OpsTarget target = machine.getTarget(sshKey);
            failed |= processDataItems(controller, dataItems, machineItem, machine, target);
        }
    }
    if (failed) {
        throw new OpsException("Could not update all servers").setRetry(TimeSpan.ONE_MINUTE);
    }
}
Also used : OpsException(org.platformlayer.ops.OpsException) OpsTarget(org.platformlayer.ops.OpsTarget) ItemBase(org.platformlayer.core.model.ItemBase) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) OpsContext(org.platformlayer.ops.OpsContext) Machine(org.platformlayer.ops.Machine)

Example 72 with OpsException

use of org.platformlayer.ops.OpsException in project platformlayer by platformlayer.

the class ZookeeperStatusChecker method handler.

@Handler
public void handler(OpsTarget target, ZookeeperServer zookeeperServer) throws OpsException {
    if (OpsContext.isConfigure() || OpsContext.isValidate()) {
        int port = ZookeeperConstants.ZK_PUBLIC_PORT;
        List<EndpointInfo> endpoints = EndpointInfo.findEndpoints(zookeeperServer.getTags(), port);
        EndpointInfo endpoint = EndpointChooser.any().choose(endpoints);
        if (endpoint == null) {
            throw new OpsException("Cannot find endpoint for zookeeper");
        }
        InetSocketAddress socketAddress = endpoint.asSocketAddress();
        {
            ZookeeperResponse response;
            try {
                // IPV6 requires ipsec; use the IPV4 loopback instead
                socketAddress = new InetSocketAddress(InetAddresses.forString("127.0.0.1"), socketAddress.getPort());
                response = ZookeeperUtils.sendCommand(target, socketAddress, "ruok");
                Deviations.assertEquals("imok", response.getRaw(), "Zookeeper ruok status");
            } catch (OpsException e) {
                Deviations.fail("Unable to connect to zookeeper", e);
            }
        }
        {
            ZookeeperResponse response;
            try {
                response = ZookeeperUtils.sendCommand(target, socketAddress, "srvr");
                Map<String, String> responseMap = response.asMap();
                String mode = responseMap.get("Mode");
                Deviations.assertIn(Arrays.asList("follower", "leader"), mode, "Zookeeper mode");
            } catch (OpsException e) {
                Deviations.fail("Unable to connect to zookeeper", e);
            }
        }
    }
}
Also used : EndpointInfo(org.platformlayer.core.model.EndpointInfo) OpsException(org.platformlayer.ops.OpsException) ZookeeperResponse(org.platformlayer.service.zookeeper.ops.ZookeeperUtils.ZookeeperResponse) InetSocketAddress(java.net.InetSocketAddress) Map(java.util.Map) Handler(org.platformlayer.ops.Handler)

Example 73 with OpsException

use of org.platformlayer.ops.OpsException in project platformlayer by platformlayer.

the class PostgresqlServerController method addChildren.

@Override
protected void addChildren() throws OpsException {
    PostgresqlTemplateVariables template = injected(PostgresqlTemplateVariables.class);
    InstanceBuilder instance = InstanceBuilder.build(model.dnsName, this, model.getTags());
    // TODO: Memory _really_ needs to be configurable here!
    instance.publicPorts.add(5432);
    instance.minimumMemoryMb = 2048;
    addChild(instance);
    instance.addChild(PackageDependency.build("postgresql"));
    instance.addChild(PackageDependency.build("postgresql-client"));
    String postgresVersion = template.getPostgresVersion();
    if (postgresVersion.equals("8.4")) {
        instance.addChild(TemplatedFile.build(template, new File("/etc/postgresql/8.4/main/pg_hba.conf"), "8_4_pg_hba.conf"));
        instance.addChild(TemplatedFile.build(template, new File("/etc/postgresql/8.4/main/postgresql.conf"), "8_4_postgresql.conf"));
    } else if (postgresVersion.equals("9.1")) {
        instance.addChild(TemplatedFile.build(template, new File("/etc/postgresql/9.1/main/pg_hba.conf"), "9_1_pg_hba.conf"));
        instance.addChild(TemplatedFile.build(template, new File("/etc/postgresql/9.1/main/postgresql.conf"), "9_1_postgresql.conf"));
    } else {
        throw new OpsException("Unsupported postgres version: " + postgresVersion);
    }
    instance.addChild(PostgresqlServerBootstrap.build());
    instance.addChild(MetricsInstance.class);
    {
        PublicEndpoint endpoint = injected(PublicEndpoint.class);
        // endpoint.network = null;
        endpoint.publicPort = 5432;
        endpoint.backendPort = 5432;
        endpoint.dnsName = model.dnsName;
        endpoint.tagItem = model.getKey();
        endpoint.parentItem = model.getKey();
        instance.addChild(endpoint);
    }
    instance.addChild(ManagedService.build("postgresql"));
    instance.addChild(injected(PostgresqlServerBackup.class));
}
Also used : OpsException(org.platformlayer.ops.OpsException) PublicEndpoint(org.platformlayer.ops.networks.PublicEndpoint) TemplatedFile(org.platformlayer.ops.filesystem.TemplatedFile) File(java.io.File) InstanceBuilder(org.platformlayer.ops.instances.InstanceBuilder)

Example 74 with OpsException

use of org.platformlayer.ops.OpsException in project platformlayer by platformlayer.

the class ZookeeperContext method buildZk.

public CuratorFramework buildZk(List<String> dnsNames) throws OpsException {
    String connectionString = Joiner.on(",").join(dnsNames);
    Builder builder = CuratorFrameworkFactory.builder();
    builder.connectString(connectionString);
    TimeSpan retryInterval = TimeSpan.FIVE_SECONDS;
    RetryPolicy retryPolicy = new RetryOneTime((int) retryInterval.getTotalMilliseconds());
    builder.retryPolicy(retryPolicy);
    CuratorFramework curatorFramework;
    try {
        curatorFramework = builder.build();
    } catch (IOException e) {
        throw new OpsException("Error building zookeeper connection", e);
    }
    return curatorFramework;
// TimeSpan sessionTimeout = TimeSpan.TEN_SECONDS;
//
// ZooKeeper zk = new ZooKeeper(connectionString, (int) sessionTimeout.getTotalMilliseconds(), this);
// return zk;
}
Also used : TimeSpan(com.fathomdb.TimeSpan) CuratorFramework(com.netflix.curator.framework.CuratorFramework) OpsException(org.platformlayer.ops.OpsException) RetryOneTime(com.netflix.curator.retry.RetryOneTime) Builder(com.netflix.curator.framework.CuratorFrameworkFactory.Builder) IOException(java.io.IOException) RetryPolicy(com.netflix.curator.RetryPolicy)

Example 75 with OpsException

use of org.platformlayer.ops.OpsException in project platformlayer by platformlayer.

the class NexusBootstrap method encryptNexusPassword.

private String encryptNexusPassword(String ldapPassword) throws OpsException {
    NexusLdapPasswords nexusLdapPasswords = new NexusLdapPasswords();
    nexusLdapPasswords.addEscapeCharacters = false;
    try {
        return nexusLdapPasswords.encrypt(ldapPassword);
    } catch (Exception e) {
        ExceptionUtils.handleInterrupted(e);
        throw new OpsException("Error encrypting password", e);
    }
}
Also used : OpsException(org.platformlayer.ops.OpsException) NexusLdapPasswords(org.platformlayer.service.nexus.utils.NexusLdapPasswords) OpsException(org.platformlayer.ops.OpsException) IOException(java.io.IOException)

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