Search in sources :

Example 16 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 17 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 18 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)

Example 19 with OpsException

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

the class LdapMasterPassword method doOperation.

@Handler
public void doOperation(OpsTarget target) throws OpsException {
    // TODO: Make this idempotent
    LdifRecord configLdif;
    {
        Command ldapSearch = Command.build("ldapsearch -Q -LLL -Y EXTERNAL -H ldapi:/// -b cn=config olcRootDN=cn=admin,cn=config dn olcRootDN olcRootPW");
        List<LdifRecord> ldifs = LdifRecord.parse(target.executeCommand(ldapSearch).getStdOut());
        if (ldifs.size() != 1) {
            throw new OpsException("Expected exactly one LDIF record for config");
        }
        configLdif = ldifs.get(0);
    }
    {
        StringBuilder modify = new StringBuilder();
        modify.append("dn: " + configLdif.getLdapDn().toString() + "\n");
        modify.append("replace: olcRootPW\n");
        modify.append("olcRootPW: " + LdapPasswords.getLdapPasswordEncoded(ldapSecret.plaintext()) + "\n");
        modify.append("\n");
        File tempDir = target.createTempDir();
        File modifyFile = new File(tempDir, "modifypw.ldif");
        FileUpload.upload(target, modifyFile, modify.toString());
        Command ldapModify = Command.build("ldapmodify -Q -Y EXTERNAL -H ldapi:/// -f {0}", modifyFile);
        target.executeCommand(ldapModify);
    }
    ldap.writeLdapServerPassword(target, ldapSecret);
}
Also used : OpsException(org.platformlayer.ops.OpsException) Command(org.platformlayer.ops.Command) List(java.util.List) File(java.io.File) Handler(org.platformlayer.ops.Handler)

Example 20 with OpsException

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

the class SmartDeserialization method deserialize.

public static <T> T deserialize(Class<T> c, InputStream is) throws OpsException {
    // TODO: Auto-detect XML, JSON, others?
    String data;
    try {
        data = IoUtils.readAll(is);
    } catch (IOException e) {
        throw new OpsException("Error reading data", e);
    }
    Format format = null;
    for (int i = 0; i < data.length(); i++) {
        char firstChar = data.charAt(i);
        switch(firstChar) {
            case ' ':
                continue;
            case '<':
                format = Format.XML;
                break;
            case '{':
                format = Format.JSON;
                break;
            default:
                {
                    if (Character.isLetter(firstChar)) {
                        format = Format.PROPERTIES;
                    } else {
                        throw new IllegalArgumentException("Unhandled character: " + ((int) firstChar));
                    }
                    break;
                }
        }
        if (format != null) {
            break;
        }
    }
    if (format == null) {
        throw new IllegalStateException("Could not determine format");
    }
    if (format == Format.XML) {
        JaxbHelper jaxb = JaxbHelper.get(c);
        try {
            return jaxb.deserialize(new StringReader(data), c);
        } catch (UnmarshalException e) {
            throw new OpsException("Error deserializing item", e);
        }
    } else {
        throw new UnsupportedOperationException();
    }
}
Also used : OpsException(org.platformlayer.ops.OpsException) UnmarshalException(javax.xml.bind.UnmarshalException) JaxbHelper(org.platformlayer.xml.JaxbHelper) StringReader(java.io.StringReader) 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