Search in sources :

Example 1 with PersistentInstance

use of org.platformlayer.service.instancesupervisor.v1.PersistentInstance in project platformlayer by platformlayer.

the class MemcachedServiceController method doOperation.

public void doOperation(Managed<MemcachedService> managed) throws OpsException, IOException {
    String key = managed.getConductorId();
    SshKey sshKey = service.getSshKey();
    Tag tag = new Tag(Tag.CONDUCTOR_ID, key);
    DiskImageRecipe recipe = imageFactory.loadDiskImageResource(getClass(), "DiskImageRecipe.xml");
    String securityGroup = service.getSecurityGroupName();
    // TODO: This needs to be configurable. Use tags?
    int minimumMemoryMb = 2048;
    Managed<PersistentInstance> foundPersistentInstance = persistentInstances.getOrCreate(tag, recipe, managed.getModel().dnsName, sshKey.getName(), securityGroup, minimumMemoryMb);
    OpenstackComputeMachine machine = persistentInstances.getMachine(foundPersistentInstance);
// KeyPair sshKey = sshKeys.getOrCreate(sshKeyName);
// OpsTarget target = machine.getTarget(sshKey);
//
// target.mkdir(new File("/opt/scripts"));
// target.setFileContents(new File("/opt/scripts/dnsdatabasemonitor"),
// ResourceUtils.loadString(getClass(), "dnsdatabasemonitor"));
// target.setFileContents(new
// File("/etc/monit/conf.d/dnsdatabasemonitor"),
// ResourceUtils.loadString(getClass(), "monitrc"));
}
Also used : SshKey(org.platformlayer.ops.helpers.SshKey) DiskImageRecipe(org.platformlayer.service.imagefactory.v1.DiskImageRecipe) PersistentInstance(org.platformlayer.service.instancesupervisor.v1.PersistentInstance) Tag(org.platformlayer.conductor.Tag) OpenstackComputeMachine(org.platformlayer.ops.OpenstackComputeMachine)

Example 2 with PersistentInstance

use of org.platformlayer.service.instancesupervisor.v1.PersistentInstance in project platformlayer by platformlayer.

the class GitServerController method doOperation.

public void doOperation(Managed<GitServer> managed) throws OpsException, IOException {
    initializeService();
    GitServer model = (GitServer) managed.getModel();
    Tag tag = new Tag(Tag.CONDUCTOR_ID, managed.getConductorId());
    SshKey sshKey = service.getSshKey();
    DiskImageRecipe recipe = imageFactory.loadDiskImageResource(getClass(), "DiskImageRecipe.xml");
    String securityGroup = service.getSecurityGroupName();
    // Git isn't particularly memory intensive (?)
    int minimumMemoryMB = 256;
    Managed<PersistentInstance> foundPersistentInstance = persistentInstances.getOrCreate(tag, recipe, model.dnsName, sshKey.getName(), securityGroup, minimumMemoryMB);
    OpenstackComputeMachine machine = persistentInstances.getMachine(foundPersistentInstance);
    OpsTarget target = machine.getTarget(sshKey);
    // target.mkdir(new File("/opt/scripts"));
    // target.setFileContents(new File("/opt/scripts/dnsdatabasemonitor"),
    // ResourceUtils.loadString(getClass(), "dnsdatabasemonitor"));
    // target.setFileContents(new
    // File("/etc/monit/conf.d/dnsdatabasemonitor"),
    // ResourceUtils.loadString(getClass(), "monitrc"));
    String adminUser = "gitadmin";
    target.executeCommand("adduser --group --system {0}", adminUser);
    File adminHomeDir = new File("/home", adminUser);
    File adminSshDir = new File(adminHomeDir, ".ssh");
    File privateKeyFile = new File(adminSshDir, "id_rsa");
    File publicKeyFile = new File(adminSshDir, "id_rsa.pub");
    File authorizedKeys = new File(adminSshDir, "authorized_keys");
    target.mkdir(adminSshDir);
    String passphrase = "";
    target.executeCommand("ssh-keygen -t rsa -f {0} -P {1}", privateKeyFile, passphrase);
    String privateKeyData = target.readTextFile(privateKeyFile);
    String publicKeyData = target.readTextFile(publicKeyFile);
    target.executeCommand("cat {0} | sudo -H -u gitosis gitosis-init", publicKeyFile);
    target.setFileContents(authorizedKeys, publicKeyData);
    target.executeCommand("chown -R {0} {1}", adminUser, adminSshDir);
    target.executeCommand("chmod -R 600 {0}", adminSshDir);
    target.executeCommand("chmod 700 {0}", adminSshDir);
    target.executeCommand("chsh -s /bin/bash {0}", adminUser);
    SshKey adminSshKey = new SshKey(null, adminUser, KeyPairUtils.deserialize(privateKeyData));
    OpsTarget adminTarget = machine.getTarget(adminSshKey);
    {
        ProcessExecution execution = adminTarget.executeCommand("ssh-keyscan 127.0.0.1");
        File knownHosts = new File(adminSshDir, "known_hosts");
        adminTarget.setFileContents(knownHosts, execution.getStdOut());
    }
// adminTarget.executeCommand("git clone gitosis@127.0.0.1:gitosis-admin.git /home/gitadmin/gitosis-admin");
// adminSshKey.
//
// adminTarget.executeCommand("git clone git@)
// git clone git@YOUR_SERVER_HOSTNAME:gitosis-admin.git
// cd gitosis-admin
}
Also used : SshKey(org.platformlayer.ops.helpers.SshKey) OpsTarget(org.platformlayer.ops.OpsTarget) DiskImageRecipe(org.platformlayer.service.imagefactory.v1.DiskImageRecipe) PersistentInstance(org.platformlayer.service.instancesupervisor.v1.PersistentInstance) GitServer(org.platformlayer.service.gitosis.model.GitServer) ProcessExecution(org.platformlayer.ops.process.ProcessExecution) Tag(org.platformlayer.conductor.Tag) OpenstackComputeMachine(org.platformlayer.ops.OpenstackComputeMachine) File(java.io.File)

Example 3 with PersistentInstance

use of org.platformlayer.service.instancesupervisor.v1.PersistentInstance 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

DiskImageRecipe (org.platformlayer.service.imagefactory.v1.DiskImageRecipe)3 PersistentInstance (org.platformlayer.service.instancesupervisor.v1.PersistentInstance)3 Tag (org.platformlayer.conductor.Tag)2 OpenstackComputeMachine (org.platformlayer.ops.OpenstackComputeMachine)2 SshKey (org.platformlayer.ops.helpers.SshKey)2 File (java.io.File)1 OpenstackClientException (org.platformlayer.OpenstackClientException)1 OpsException (org.platformlayer.ops.OpsException)1 OpsTarget (org.platformlayer.ops.OpsTarget)1 ProcessExecution (org.platformlayer.ops.process.ProcessExecution)1 GitServer (org.platformlayer.service.gitosis.model.GitServer)1 GraphiteService (org.platformlayer.service.graphite.model.GraphiteService)1