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));
}
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;
}
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);
}
}
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);
}
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();
}
}
Aggregations