Package org.platformlayer.ops

Examples of org.platformlayer.ops.OpsException


  public String findData(ProjectId projectId, ServiceType serviceType, ServiceMetadataKey keyId) throws OpsException {
    String keyData;
    try {
      keyData = serviceAuthorizationService.findPrivateData(serviceType, projectId, keyId);
    } catch (RepositoryException e) {
      throw new OpsException("Error reading from repository", e);
    }
    return keyData;
  }
View Full Code Here


      saveKeypairInDevelopment(projectId, serviceType, keyPair);

      return keyPair;
    } catch (IOException e) {
      throw new OpsException("Error deserializing SSH key", e);
    }
  }
View Full Code Here

      // saveKeypairInDevelopment(projectId, serviceType, keyPair);

      return cert;
    } catch (IllegalArgumentException e) {
      throw new OpsException("Error deserializing certificate", e);
    }
  }
View Full Code Here

      throws OpsException {
    String serialized;
    try {
      serialized = KeyPairUtils.serialize(keyPair);
    } catch (IOException e) {
      throw new OpsException("Error serializing key pair", e);
    }
    try {
      serviceAuthorizationService.setPrivateData(serviceType, project, keyId, serialized);
    } catch (RepositoryException e) {
      throw new OpsException("Error writing to repository", e);
    }

    saveKeypairInDevelopment(project, serviceType, keyPair);
  }
View Full Code Here

      List<X509Certificate> chain) throws OpsException {
    String serialized;
    try {
      serialized = CertificateUtils.toPem(chain);
    } catch (IllegalArgumentException e) {
      throw new OpsException("Error serializing certificate", e);
    }
    try {
      serviceAuthorizationService.setPrivateData(serviceType, projectId, keyId, serialized);
    } catch (RepositoryException e) {
      throw new OpsException("Error writing to repository", e);
    }

    // saveKeypairInDevelopment(project, serviceType, cert);
  }
View Full Code Here

        try {
          String serialized = KeyPairUtils.serialize(keyPair);
          IoUtils.writeAll(keyFile, serialized);
        } catch (IOException e) {
          throw new OpsException("Error serializing SSH key", e);
        }
      }

      String sshPublicKey = OpenSshUtils.serialize(keyPair.getPublic());
      log.info("SSH public key for " + serviceType + ":" + project + " is " + sshPublicKey);
View Full Code Here

  public X509Certificate parseFirst(String cert) throws OpsException {
    CertificateReader reader = new CertificateReader();
    X509Certificate[] parsed = reader.parse(cert);
    if (parsed == null || parsed.length == 0) {
      throw new OpsException("Cannot parse certificate");
    } else {
      return parsed[0];
    }
  }
View Full Code Here

      Server server = computeClient.root().servers().server(serverId).show();
      return server;
    } catch (OpenstackNotFoundException e) {
      return null;
    } catch (OpenstackException e) {
      throw new OpsException("Error getting server", e);
    }
  }
View Full Code Here

          if (createdSecurityGroup != null) {
            // Ignore
            log.warn("Ignoring 'security group already exists' error: " + e.getMessage());
          } else {
            throw new OpsException("Error creating security group", e);
          }
        }
        {
          CreateSecurityGroupRuleRequest newRule = new CreateSecurityGroupRuleRequest();
          newRule.setCidr("0.0.0.0/0");
          newRule.setFromPort(22);
          newRule.setToPort(22);
          newRule.setIpProtocol("tcp");
          newRule.setParentGroupId(createdSecurityGroup.getId());

          try {
            log.info("Creating security group rule for port: " + newRule.getToPort());
            SecurityGroupRule createdRule = computeClient.root().securityGroupRules().create(newRule);
          } catch (OpenstackException e) {
            String message = e.getMessage();
            if (message != null && message.contains("This rule already exists")) {
              log.warn("Ignoring 'rule already exists': " + e.getMessage());
            } else {
              throw new OpsException("Error creating security group access", e);
            }
          }
        }
      }

      AsyncServerOperation createServerOperation;
      {
        ServerForCreate create = new ServerForCreate();

        create.setName(serverName);

        if (request.sshPublicKey != null) {
          if (cloudBehaviours.supportsPublicKeys()) {
            OpenstackCloudHelpers cloudHelpers = new OpenstackCloudHelpers();
            KeyPair keyPair = cloudHelpers.ensurePublicKeyUploaded(computeClient, request.sshPublicKeyName,
                request.sshPublicKey);
            create.setKeyName(keyPair.getName());
          } else if (cloudBehaviours.supportsFileInjection()) {
            String fileContents = SshKeys.serialize(request.sshPublicKey);
            create.addUploadFile("/root/.ssh/authorized_keys", Utf8.getBytes(fileContents));
          } else {
            throw new OpsException("No supported SSH key mechanism on cloud");
          }
        }

        create.setImageRef(foundImage.getId());

        Flavor flavor = getClosestInstanceType(computeClient, request);
        if (flavor == null) {
          throw new OpsException("Cannot determine instance type for request");
        }
        create.setFlavorRef(flavor.getId());

        if (request.securityGroups != null) {
          // TODO: Reimplement if needed
          throw new UnsupportedOperationException();
        }

        if (createdSecurityGroup != null) {
          ServerForCreate.SecurityGroup serverSecurityGroup = new ServerForCreate.SecurityGroup();
          serverSecurityGroup.setName(createdSecurityGroup.getName());
          create.getSecurityGroups().add(serverSecurityGroup);
        }

        create.setConfigDrive(cloudBehaviours.useConfigDrive());

        log.info("Launching new server: " + create.getName());
        createServerOperation = computeClient.createServer(create);
      }

      log.info("Waiting for server to be ready");
      Server server = createServerOperation.waitComplete();
      Server instanceInfo = null;
      String stateName = null;
      while (true) {
        instanceInfo = getInstanceInfo(computeClient, server.getId());

        stateName = instanceInfo.getStatus();
        log.info("Instance state: " + stateName);

        // if (stateName.equals("scheduling")) {
        // continue;
        // }
        //
        if (stateName.equals("BUILD")) {
          break;
        }

        // if (stateName.equals("shutdown")) {
        // break;
        // }

        if (stateName.equals("ACTIVE")) {
          break;
        }

        Thread.sleep(1000);
      }

      // OpenstackComputeMachine machine = new OpenstackComputeMachine(instanceInfo.getAccessIPv4(), this,
      // server.getId());

      // Even if the machine is in 'error' state, we still want to associate it with us
      if (request.tags != null) {
        Server newServerInfo = new Server();
        Metadata metadata = new Metadata();
        for (Tag tag : request.tags) {
          Metadata.Item meta = new Metadata.Item();
          meta.setKey(tag.getKey());
          meta.setValue(tag.getValue());
          metadata.getItems().add(meta);
        }

        newServerInfo.setMetadata(metadata);
        log.info("Tagging server: " + server.getId());
        computeClient.root().servers().server(server.getId()).update(newServerInfo);
      }

      return server;
    } catch (InterruptedException e) {
      ExceptionUtils.handleInterrupted(e);
      throw new OpsException("Error building server", e);
    } catch (OpenstackException e) {
      throw new OpsException("Error building server", e);
    }
  }
View Full Code Here

      return deleteOperation;
    } catch (OpenstackNotFoundException e) {
      log.info("Could not find instance to be terminated, assuming already terminated: " + instanceId);
      return null;
    } catch (OpenstackException e) {
      throw new OpsException("Error terminating server", e);
    }
  }
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.