Package org.platformlayer.ops

Examples of org.platformlayer.ops.OpsException


        SearchScope.Base);
    if (results.size() == 0) {
      return null;
    }
    if (results.size() != 1) {
      throw new OpsException("Got multiple LDAP results, expecting one for " + searchBaseDN);
    }
    return results.get(0);
  }
View Full Code Here


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

    {
View Full Code Here

      } catch (ProcessExecutionException e) {
        ProcessExecution execution = e.getExecution();
        if (execution.getExitCode() == 1 && execution.getStdErr().contains("Device not found")) {
          found = false;
        } else {
          throw new OpsException("Error checking for interface", e);
        }
      }

      if (!found) {
        // This is actually idempotent, but I think it's scary to rely on it being so
        Command command = Command.build("/usr/sbin/tunctl -t {0}", interfaceName);
        target.executeCommand(command);
      }

      {
        // TODO: Safe to re-run?
        Command command = Command.build("ifconfig {0} up", interfaceName);
        target.executeCommand(command);
      }

      if (bridgeName != null) {
        // TODO: Safe to re-run?

        Command command = Command.build("brctl addif {0} {1}", bridgeName.get(), interfaceName);
        try {
          target.executeCommand(command);
        } catch (ProcessExecutionException e) {
          ProcessExecution execution = e.getExecution();
          if (execution.getExitCode() == 1 && execution.getStdErr().contains("already a member of a bridge")) {
            // OK
            // TODO: Check that the bridge is bridgeName
          } else {
            throw new OpsException("Error attaching interface to bridge", e);
          }
        }
      }
    }
View Full Code Here

    if (OpsContext.isConfigure()) {
      if (assignedTo == null) {
        List<GitService> gitServices = platformLayer.listItems(GitService.class);

        if (gitServices.size() == 0) {
          throw new OpsException("No git service found");
        }

        GitService gitService = RandomChooser.chooseRandom(gitServices);

        if (gitService == null) {
          throw new IllegalStateException();
        }

        assignedTo = gitService.getKey();
        platformLayer.addTag(model.getKey(), Tag.ASSIGNED_TO.build(assignedTo));
      }
    }

    GitService gitService = null;
    if (assignedTo != null) {
      gitService = platformLayer.getItem(assignedTo, GitService.class);
    }

    if (OpsContext.isDelete()) {
      if (gitService == null) {
        log.info("Deleting, but not assigned to a server; nothing to do");
        getRecursionState().setPreventRecursion(true);
        return;
      }
    }

    if (gitService == null) {
      throw new OpsException("No git servers found");
    }

    if (gitService.getState() != ManagedItemState.ACTIVE) {
      throw new OpsException("Server not yet active: " + gitService);
    }

    Machine machine = instances.findMachine(gitService);
    if (machine == null) {
      throw new OpsException("Server machine not found:" + gitService);
    }

    SshKey sshKey = service.getSshKey();
    OpsTarget target = machine.getTarget(sshKey);
View Full Code Here

    {
      RunScript script = dbConnection.addChild(RunScript.class);
      try {
        script.sql = ResourceUtils.get(getClass(), "schema.sql");
      } catch (IOException e) {
        throw new OpsException("Error loading SQL script resource", e);
      }
    }
  }
View Full Code Here

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

      String key = entry.getKey();
      String value = entry.getValue();

      int dotIndex = key.indexOf('.');
      if (dotIndex == -1) {
        throw new OpsException("Invalid key format: " + key);
      }

      String heading = key.substring(0, dotIndex);
      String subKey = key.substring(dotIndex + 1);
View Full Code Here

    URI url;
    try {
      url = new URI(endpoint);
    } catch (URISyntaxException e) {
      throw new OpsException("Cannot parse endpoint: " + endpoint, e);
    }
    // if (url.getScheme().equals("glance")) {
    // int port = url.getPort();
    // if (port == -1)
    // port = 9292;
    // String glanceUrl = "http://" + url.getHost() + ":" + port + "/v1";
    // GlanceImageStore glanceImageStore = new GlanceImageStore(glanceUrl);
    // return glanceImageStore;
    // } else

    if (url.getScheme().equals("ssh")) {
      String myAddress = url.getHost();
      Machine machine = new OpaqueMachine(NetworkPoint.forPublicHostname(myAddress));
      // This is nasty; we're in the context of another service here...
      SshKey sshKey = sshKeys.findOtherServiceKey(new ServiceType("imagestore"));
      OpsTarget target = machine.getTarget("imagestore", sshKey.getKeyPair());

      DirectImageStore directImageStore = OpsContext.get().getInjector().getInstance(DirectImageStore.class);
      directImageStore.connect(target);
      return directImageStore;
    } else {
      throw new OpsException("Unknown protocol for endpoint: " + endpoint);
    }
  }
View Full Code Here

    nexusLdapPasswords.addEscapeCharacters = false;
    try {
      return nexusLdapPasswords.encrypt(ldapPassword);
    } catch (Exception e) {
      ExceptionUtils.handleInterrupted(e);
      throw new OpsException("Error encrypting password", e);
    }
  }
View Full Code Here

    Document dom;
    try {
      boolean isNamespaceAware = true;
      dom = XmlHelper.parseXmlDocument(is, isNamespaceAware);
    } catch (ParserConfigurationException e) {
      throw new OpsException("Error parsing XML template", e);
    } catch (SAXException e) {
      throw new OpsException("Error parsing XML template", e);
    } catch (IOException e) {
      throw new OpsException("Error parsing XML template", e);
    }

    SolrTemplateData template = OpsContext.get().getInjector().getInstance(SolrTemplateData.class);

    Element fieldsElement;
    {
      NodeList fieldsList = dom.getElementsByTagName("fields");
      if (fieldsList.getLength() != 1) {
        throw new OpsException("Expected exactly one fields element");
      }

      fieldsElement = (Element) fieldsList.item(0);
    }
View Full Code Here

TOP

Related Classes of org.platformlayer.ops.OpsException

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.