Package org.platformlayer.ops

Examples of org.platformlayer.ops.OpsException


  public List<JobData> listRecentJobs(JobQuery query) throws OpsException {
    List<JobData> jobs;
    try {
      jobs = jobRepository.listRecentJobs(query);
    } catch (RepositoryException e) {
      throw new OpsException("Error querying for jobs", e);
    }

    return jobs;
  }
View Full Code Here


        XPath xpath = xPathfactory.newXPath();
        XPathExpression expr = xpath
            .compile("/response/lst[@name='status']/lst/date[@name='startTime']/text()");
        return (String) expr.evaluate(dom, XPathConstants.STRING);
      } catch (XPathExpressionException e) {
        throw new OpsException("Error reading value from XML", e);
      }
    }
View Full Code Here

    }

    String message = "Invalid multitenant configuration";

    if (username == null || projectKey == null) {
      throw new OpsException(message);
    }

    AuthenticationToken authn = null;

    if (certificateAndKey != null) {
      try {
        authn = authenticationService.authenticateWithCertificate(username, certificateAndKey.getPrivateKey(),
            certificateAndKey.getCertificateChain());
      } catch (PlatformlayerAuthenticationClientException e) {
        throw new OpsException(message, e);
      }
    } else if (password != null) {
      log.warn("Using password authentication with multitenant");

      if (!ApplicationMode.isDevelopment()) {
        throw new IllegalStateException();
      }

      try {
        authn = authenticationService.authenticateWithPassword(username, password);
      } catch (PlatformlayerAuthenticationClientException e) {
        throw new OpsException(message, e);
      }
    }

    if (authn == null) {
      throw new OpsException(message);
    }

    ProjectAuthorization authz = authenticationTokenValidator.validateToken(authn, projectKey);
    if (authz == null) {
      throw new OpsException(message);
    }

    // {
    // try {
    // project = userRepository.findProject(user, projectKey);
    // } catch (RepositoryException e) {
    // throw new OpsException(message, e);
    // }
    //
    // if (project == null) {
    // throw new OpsException(message);
    // }
    // }

    List<PlatformLayerKey> mappedItems = Lists.newArrayList();

    for (String key : Splitter.on(",").split(configuration.lookup("multitenant.keys", ""))) {
      String[] tokens = key.split("/");
      if (tokens.length != 2) {
        throw new IllegalStateException();
      }
      String serviceType = tokens[0];
      String itemType = tokens[1];
      mappedItems.add(PlatformLayerKey.fromServiceAndItem(serviceType, itemType));
    }

    if (mappedItems.isEmpty()) {
      throw new OpsException(message);
    }

    MultitenantConfiguration config = new SimpleMultitenantConfiguration(authz, mappedItems);

    return config;
View Full Code Here

    try {
      String logCookie = jobLogStore.saveJobLog(jobKey, executionId, startTime, logger);
      jobRepository.recordJobEnd(jobKey, executionId, endTime, state, logCookie);
    } catch (RepositoryException e) {
      throw new OpsException("Error writing job to repository", e);
    } catch (Exception e) {
      throw new OpsException("Error writing job log", e);
    }
  }
View Full Code Here

    case 200:
      break;
    case 201:
      break;
    default:
      throw new OpsException("Unexpected result code while uploading backup: " + httpResult + " Result="
          + curlResult);
    }

  }
View Full Code Here

  @Override
  public OpenstackBackupContext build(ItemBase item) throws OpsException {
    Machine machine = instances.findMachine(item);
    if (machine == null) {
      throw new OpsException("Cannot determine machine for: " + item);
    }
    StorageConfiguration storageConfiguration = cloud.getStorageConfiguration(machine);
    return build(storageConfiguration);
  }
View Full Code Here

  public void doOperation() throws OpsException, IOException {
    Tags instanceTags = instance.getTags();

    OpenstackCloud cloud = findCloud();
    if (cloud == null) {
      throw new OpsException("Could not find cloud");
    }
    OpenstackComputeClient computeClient = openstack.getComputeClient(cloud);

    getRecursionState().pushChildScope(cloud);

    List<String> assignedInstanceIds = instanceTags.findAll(Tag.ASSIGNED);
    if (assignedInstanceIds.isEmpty()) {
      if (createInstance && !OpsContext.isDelete()) {
        MachineCreationRequest request = buildMachineCreationRequest();

        PlatformLayerKey instanceKey = instance.getKey();
        request.tags.add(Tag.buildParentTag(instanceKey));

        String serverName = buildServerName();

        Server created = openstack.createInstance(cloud, serverName, request);

        {
          Tag instanceTag = Tag.build(Tag.ASSIGNED, created.getId());
          platformLayer.addTag(instance.getKey(), instanceTag);
        }

        assignedInstanceIds.add(created.getId());
      }
    }

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

    Machine machine = null;
    OpsTarget target = null;

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

      // We just take the first instance id
      String assignedInstanceId = Iterables.getFirst(assignedInstanceIds, null);

      Server server = openstack.findServerById(cloud, assignedInstanceId);

      if (server == null) {
        if (OpsContext.isConfigure()) {
          throw new OpsException("Unable to find assigned server: " + assignedInstanceId);
        }
      } else {
        server = openstack.ensureHasPublicIp(cloud, server);

        AsyncServerOperation powerOnOperation = openstack.ensurePoweredOn(cloud, server);
View Full Code Here

  private void waitOperation(AsyncServerOperation operation) throws OpsException {
    try {
      log.info("Waiting for server operation to complete");
      operation.waitComplete(2, TimeUnit.MINUTES);
    } catch (TimeoutException e) {
      throw new OpsException("Timeout waiting for server operation to complete", e);
    } catch (OpenstackException e) {
      throw new OpsException("Error waiting for server operation to complete", e);
    }
  }
View Full Code Here

        }

        List<String> tokens = Lists.newArrayList(Splitter.on(CharMatcher.WHITESPACE).omitEmptyStrings()
            .split(line));
        if (tokens.size() != 2) {
          throw new OpsException("Error parsing line; expected 2 items: " + line);
        }
        String state = tokens.get(1);
        if (state.equals("install")) {
          String packageName = tokens.get(0);
          int colonIndex = packageName.indexOf(':');
          if (colonIndex != -1) {
            // Architecture sometimes follows package name
            packageName = packageName.substring(0, colonIndex);
          }
          packages.add(packageName);
        } else if (state.equals("deinstall")) {
          // Not installed (?)
        } else {
          throw new OpsException("Unknown package state in line: " + line);
        }
      }
      cached.installedPackages = packages;
    } else {
      log.debug("Re-using cached package info");
View Full Code Here

              log.warn("Retrying apt command");
              continue;
            }
          }
        }
        throw new OpsException("Error executing apt command", e);
      }
      return;
    }
  }
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.