Package org.platformlayer.ops

Examples of org.platformlayer.ops.OpsTarget


  public void doRecurseOperation() throws OpsException {
    ItemBase dest = platformLayerHelpers.getItem(key);

    boolean required = !OpsContext.isDelete();
    for (Machine machine : instanceHelpers.getMachines(dest, required)) {
      OpsTarget target = instanceHelpers.getTarget(dest, machine);

      BindingScope scope = BindingScope.push(machine, target);
      try {
        OpsContext opsContext = OpsContext.get();
        OperationRecursor.doRecurseChildren(opsContext, this);
View Full Code Here


public class NginxServerBootstrap {

  @Handler
  public void handler() throws OpsException {
    OpsTarget target = OpsContext.get().getInstance(OpsTarget.class);

    target.rm(new File("/etc/nginx/sites-enabled/default"));
  }
View Full Code Here

        int minimumMemoryMB = 256; // Git isn't particularly memory intensive (?)
        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.
View Full Code Here

    // Do nothing
  }

  @Handler
  public void handle() throws OpsException {
    OpsTarget target = OpsContext.get().getInstance(OpsTarget.class);

    if (Strings.isNullOrEmpty(hostname)) {
      throw new IllegalArgumentException();
    }

    // Fix hostname
    File hostsFile = new File("/etc/hosts");

    String hostLine = "127.0.0.1\t" + hostname;

    String hosts = target.readTextFile(hostsFile);

    boolean found = false;
    for (String line : Splitter.on("\n").trimResults().split(hosts)) {
      if (line.equals(hostLine)) {
        found = true;
      }
    }

    if (!found) {
      hosts += "\n" + hostLine + "\n";
      FileUpload.upload(target, hostsFile, hosts);
    }

    FileUpload.upload(target, new File("/etc/hostname"), hostname);

    {
      ProcessExecution execution = target.executeCommand("hostname");
      String currentHostname = execution.getStdOut().trim();
      if (!currentHostname.equals(hostname)) {
        if (!DetectVirtualization.isLxc(target)) {
          // This actually can't be done within an LXC instance, which is why we go to extraordinary lengths
          // to
          // set it on creation
          target.executeCommand("hostname {0}", hostname);
        } else {
          log.warn("Unable to change hostname on LXC: " + currentHostname + " -> " + hostname);
        }
      }
    }
View Full Code Here

  public void upload(TargetServer targetServer, ZoneFile zoneFile) throws OpsException {
    // TODO: Validate / sanitize key
    File path = new File(DnsServerTemplate.getZonesDir(), zoneFile.getKey());
    String data = zoneFile.getData();

    OpsTarget target = targetServer.getTarget();

    String existing = target.readTextFile(path);
    boolean isSame = Objects.equal(data, existing);

    if (!isSame) {
      // TODO: The serial value means that this is always dirty
      log.info("Uploading zone file: " + path);

      // Upload then atomic move
      File tempFile = new File(targetServer.getTempDir(), zoneFile.getKey());

      FileUpload upload = FileUpload.build(data);
      upload.path = tempFile;
      upload.mode = "0644";

      target.doUpload(upload);

      target.mv(tempFile, path);
    }
  }
View Full Code Here

        log.warn("Dns server instance not found: " + dnsServer);
        failed = true;
        continue;
      }

      OpsTarget target = machine.getTarget(service.getSshKey());

      try {
        upload(target, dnsFile);
      } catch (OpsException e) {
        log.warn("Error updloading dns to server: " + dnsServer, e);
View Full Code Here

  @Handler
  public void handler(RawTarget rawTarget) throws OpsException, IOException {
    OpaqueMachine machine = new OpaqueMachine(NetworkPoint.forPublicHostname(rawTarget.host));
    SshKey serviceSshKey = service.getSshKey();
    OpsTarget target = machine.getTarget(serviceSshKey);

    // TODO: We have a bootstrapping problem here!!
    PublicKey sshPublicKey = service.getSshKey().getKeyPair().getPublic();
    SshAuthorizedKey.ensureSshAuthorization(target, "root", sshPublicKey);
  }
View Full Code Here

  @Handler(BackupAction.class)
  public void doBackup() throws OpsException, IOException {
    OpsContext opsContext = OpsContext.get();

    // Machine machine = opsContext.getInstance(Machine.class);
    OpsTarget target = opsContext.getInstance(OpsTarget.class);

    BackupContext backup = backups.getContext();

    DirectoryBackup request = new DirectoryBackup();
    request.target = target;
View Full Code Here

      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);
      }
    }
View Full Code Here

    if (assignedInstanceIds.isEmpty() && !OpsContext.isDelete()) {
      throw new OpsException("Instance not yet assigned");
    }

    GoogleComputeMachine machine = null;
    OpsTarget target = null;

    if (!assignedInstanceIds.isEmpty()) {
      if (assignedInstanceIds.size() != 1) {
        log.warn("Multiple instance ids found: " + assignedInstanceIds);
      }
View Full Code Here

TOP

Related Classes of org.platformlayer.ops.OpsTarget

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.