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