Package org.platformlayer.xaas.services

Examples of org.platformlayer.xaas.services.ServiceProvider


        ServiceProviderDictionary.class);

    ServiceType serviceType = platformLayerKey.getServiceType();
    ItemType itemType = platformLayerKey.getItemType();

    ServiceProvider serviceProvider = serviceProviderDictionary.getServiceProvider(serviceType);
    if (serviceProvider == null) {
      throw new IllegalArgumentException();
    }
    ModelClass<?> modelClass = serviceProvider.getModelClass(itemType);
    if (modelClass == null) {
      throw new IllegalArgumentException();
    }
    return modelClass;
  }
View Full Code Here


public class MetricsResource extends XaasResourceBase {
  @GET
  @Produces({ XML, JSON })
  public MetricInfoCollection listMetrics() throws OpsException, RepositoryException {
    final ItemBase managedItem = getManagedItem();
    final ServiceProvider serviceProvider = getServiceProvider();

    OpsContextBuilder opsContextBuilder = objectInjector.getInstance(OpsContextBuilder.class);

    final OpsContext opsContext = opsContextBuilder.buildTemporaryOpsContext(getServiceType(),
        getProjectAuthorization());

    return OpsContext.runInContext(opsContext, new CheckedCallable<MetricInfoCollection, Exception>() {
      @Override
      public MetricInfoCollection call() throws Exception {
        BindingScope bindingScope = BindingScope.push(managedItem, managedItem);
        try {
          Object controller = serviceProvider.getController(managedItem);
          MetricConfig metricConfig = opsContext.getMetricInfo(controller);

          return MetricCollector.toMetricInfo(metricConfig);
        } finally {
          bindingScope.pop();
View Full Code Here

  @POST
  @Produces({ XML, JSON })
  public MetricDataSource getMetrics(final MetricQuery query) throws RepositoryException, OpsException {
    final ItemBase managedItem = getManagedItem();
    final ServiceProvider serviceProvider = getServiceProvider();

    OpsContextBuilder opsContextBuilder = objectInjector.getInstance(OpsContextBuilder.class);

    final OpsContext opsContext = opsContextBuilder.buildTemporaryOpsContext(getServiceType(),
        getProjectAuthorization());

    return OpsContext.runInContext(opsContext, new CheckedCallable<MetricDataSource, Exception>() {
      @Override
      public MetricDataSource call() throws Exception {
        BindingScope bindingScope = BindingScope.push(managedItem, managedItem);
        try {
          MetricDataSource metrics = serviceProvider.getMetricValues(managedItem, query);
          return metrics;
        } finally {
          bindingScope.pop();
        }
      }
View Full Code Here

  public <T> ServiceAuthorization createService(final ServiceAuthorization authorization) throws OpsException,
      RepositoryException {
    ServiceType serviceType = getServiceType();
    authorization.serviceType = serviceType.getKey();

    final ServiceProvider serviceProvider = opsSystem.getServiceProvider(serviceType);
    if (serviceProvider == null) {
      log.warn("Unknown serviceProvider: " + serviceType);
      throw new WebApplicationException(404);
    }
View Full Code Here

    }
    final Class<T> javaClass = modelClass.getJavaClass();

    // JaxbHelper jaxbHelper = JaxbHelper.get(javaClass);

    final ServiceProvider serviceProvider = modelClass.getProvider();

    String id = item.getId();

    if (Strings.isNullOrEmpty(id)) {
      if (generateUniqueName) {
        id = serviceProvider.buildItemId(modelClass, item);
      } else {
        // TODO: We could auto-generate this, but it seems better to require it,
        // otherwise we end up with lots of randomly named items
        throw new OpsException("Must specify item id");
        // id = UUID.randomUUID().toString();
        // item.setId(id);
      }
    }

    ProjectId project = getProjectId(auth);
    PlatformLayerKey itemKey = new PlatformLayerKey(null, project, modelClass.getServiceType(),
        modelClass.getItemType(), new ManagedItemId(id));
    item.setKey(itemKey);

    item.state = ManagedItemState.CREATION_REQUESTED;

    final OpsContext opsContext = buildTemporaryOpsContext(modelClass.getServiceType(), auth);

    T created = OpsContext.runInContext(opsContext, new CheckedCallable<T, Exception>() {
      @Override
      public T call() throws Exception {
        PlatformLayerKey itemKey = item.getKey();

        T existing;

        SecretProvider secretProvider = SecretProvider.from(auth);

        if (uniqueTagKey != null) {
          boolean fetchTags = true;
          Tag uniqueTag = null;
          for (Tag tag : item.getTags()) {
            if (Objects.equal(tag.getKey(), uniqueTagKey)) {
              uniqueTag = tag;
            }
          }
          if (uniqueTag == null) {
            throw new IllegalArgumentException("Could not find unique tag");
          }
          Filter filter = TagFilter.byTag(uniqueTag);
          filter = StateFilter.excludeDeleted(filter);

          existing = null;
          List<T> existingList = repository.findAll(modelClass, itemKey.getProject(), fetchTags,
              secretProvider, filter);
          if (!existingList.isEmpty()) {
            if (existingList.size() != 1) {
              throw new IllegalArgumentException("Found multiple items with unique tag");
            }
            existing = existingList.get(0);
          }

          if (existing == null) {
            itemKey = findUniqueId(item, itemKey, secretProvider);
          }
        } else {
          if (generateUniqueName) {
            itemKey = findUniqueId(item, itemKey, secretProvider);
          }

          try {
            boolean fetchTags = true;
            existing = Casts.checkedCast(repository.getManagedItem(itemKey, fetchTags, secretProvider),
                javaClass);
          } catch (RepositoryException e) {
            throw new OpsException("Error fetching item from database", e);
          }
        }

        if (!canExist && existing != null) {
          throw new OpsException("Item already exists");
        }

        serviceProvider.beforeCreateItem(item);

        ProjectId project = getProjectId(auth);
        T newItem;
        try {
          if (existing == null) {
View Full Code Here

      throw new IllegalStateException("Item not found");
    }

    targetItem.state = ManagedItemState.DELETE_REQUESTED;

    final ServiceProvider serviceProvider = serviceProviderDirectory.getServiceProvider(targetItemKey
        .getServiceType());
    if (serviceProvider == null) {
      throw new IllegalStateException("Unknown service type");
    }
View Full Code Here

  @GET
  @Path("schema")
  @Produces({ XML })
  public String getSchema() throws IOException, JAXBException {
    ServiceProvider serviceProvider = getServiceProvider();

    String namespace = null;

    List<Class<?>> javaClasses = Lists.newArrayList();
    for (ModelClass<?> modelClass : serviceProvider.getModels().all()) {
      javaClasses.add(modelClass.getJavaClass());
      String modelNamespace = modelClass.getPrimaryNamespace();
      if (namespace == null) {
        namespace = modelNamespace;
      } else if (!namespace.equals(modelNamespace)) {
View Full Code Here

  @GET
  @Path("sshkey")
  @Produces({ TEXT_PLAIN })
  public String getSshPublicKey() throws RepositoryException, OpsException, IOException {
    final ServiceProvider serviceProvider = getServiceProvider();

    if (serviceProvider == null) {
      raiseNotFound();
    }

    OpsContextBuilder opsContextBuilder = opsContextBuilderFactory.get();
    final OpsContext opsContext = opsContextBuilder.buildTemporaryOpsContext(serviceProvider.getServiceType(),
        getProjectAuthorization());

    PublicKey publicKey = OpsContext.runInContext(opsContext, new CheckedCallable<PublicKey, Exception>() {
      @Override
      public PublicKey call() throws Exception {
        PublicKey publicKey = serviceProvider.getSshPublicKey();
        return publicKey;
      }
    });

    if (publicKey == null) {
      throw new WebApplicationException(404);
    }

    String description = "platformlayer://" + getProject().getKey() + "/"
        + serviceProvider.getServiceType().getKey();

    return OpenSshUtils.serialize(publicKey, description);
  }
View Full Code Here

    return resources;
  }

  @Path("extensions")
  public Object getExtensionsResource() throws Exception {
    final ServiceProvider serviceProvider = getServiceProvider();

    OpsContextBuilder opsContextBuilder = objectInjector.getInstance(OpsContextBuilder.class);

    final OpsContext opsContext = opsContextBuilder.buildTemporaryOpsContext(getServiceType(),
        getProjectAuthorization());

    Object extensionResource = OpsContext.runInContext(opsContext, new CheckedCallable<Object, Exception>() {
      @Override
      public Object call() throws Exception {
        return serviceProvider.getExtensionResource();
      }
    });

    if (extensionResource == null) {
      raiseNotFound();
View Full Code Here

  protected ServiceProvider getServiceProvider() {
    return serviceDictionary.getServiceProvider(getServiceType());
  }

  protected ModelClass<?> getModelClass() {
    ServiceProvider serviceProvider = getServiceProvider();
    if (serviceProvider == null) {
      log.warn("Unknown service");
      raiseNotFound();
    }
    ModelClass<?> modelClass = serviceProvider.getModels().find(getItemType());
    if (modelClass == null) {
      log.warn("Unknown itemtype: " + getItemType());
      raiseNotFound();
    }
View Full Code Here

TOP

Related Classes of org.platformlayer.xaas.services.ServiceProvider

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.