/** * @see org.jclouds.apis.Apis#withId */ protected ApiMetadata createApiMetadata() { try { return Apis.withId(provider); } catch (NoSuchElementException e) { return null; } }
@Override public Iterable<ApiMetadata> getApis() { return ImmutableSet.<ApiMetadata>builder() .addAll(transform(Apis.all(), ToApiMetadata.INSTANCE)) .build(); }
private ImmutableSortedSet<String> getAllProviders() { // correct the classloader so that jclouds extensions can be found Thread.currentThread().setContextClassLoader(Apis.class.getClassLoader()); // TODO: apis need endpoints, providers don't; do something smarter // with this stuff :) Builder<String> builder = ImmutableSet.<String> builder(); builder.addAll(Iterables.transform(Apis.viewableAs(ComputeServiceContext.class), Apis.idFunction())); builder.addAll(Iterables.transform(Providers.viewableAs(ComputeServiceContext.class), Providers.idFunction())); return ImmutableSortedSet.copyOf(builder.build()); }
/** * looks up a provider or api with the given id * * @param providerOrApi * id of the provider or api * @return means to build a context to that provider * @throws NoSuchElementException * if the id was not configured. */ public static ContextBuilder newBuilder(String providerOrApi) throws NoSuchElementException { try { try { return ContextBuilder.newBuilder(Providers.withId(providerOrApi)); } catch (NoSuchElementException e) { return ContextBuilder.newBuilder(Apis.withId(providerOrApi)); } } catch (NoSuchElementException e) { Builder<String, String> builder = ImmutableMultimap.<String, String> builder(); builder.putAll("providers", transform(Providers.all(), Providers.idFunction())); builder.putAll("apis", transform(Apis.all(), Apis.idFunction())); throw new NoSuchElementException(String.format("key [%s] not in the list of providers or apis: %s", providerOrApi, builder.build())); } }
@Override public int complete(String buffer, int cursor, List<String> candidates) { try { if (displayApisWithoutService) { for (ApiMetadata apiMetadata : Apis.viewableAs(TypeToken.of(BlobStoreContext.class))) { delegate.getStrings().add(apiMetadata.getId()); } } else if (blobStoreServices != null) { for (BlobStore blobStore : blobStoreServices) { String id = blobStore.getContext().unwrap().getId(); if (Apis.withId(id) != null) { delegate.getStrings().add(id); } } } } catch (Exception ex) { // noop } return delegate.complete(buffer, cursor, candidates); }
@Test public void testTransformableToContains() { for (TypeToken<? extends View> view : views) { ImmutableSet<ApiMetadata> ofType = ImmutableSet.copyOf(Apis.viewableAs(view)); assert ofType.contains(toTest) : String.format("%s not found in %s for %s", toTest, ofType, view); } }
/** * Returns all available apis. * * @return all available apis */ public static Iterable<ApiMetadata> all() { return ImmutableSet.<ApiMetadata>builder() .addAll(fromServiceLoader()) .addAll(ApiRegistry.fromRegistry()).build(); }
/** * this will build any {@link ApiMetadata#getViews() view} supported by the ApiMetadata. * * ex. {@code builder.build(BlobStoreContext.class) } will work, if {@code TypeToken<BlobStore>} * is a configured {@link ApiMetadata#getViews() view} of this api. * */ @SuppressWarnings("unchecked") public <V extends View> V buildView(TypeToken<V> viewType) { TypeToken<V> returnType; try { returnType = (TypeToken<V>) Apis.findView(apiMetadata, checkNotNull(viewType, "viewType")); } catch (NoSuchElementException e) { throw new IllegalArgumentException(String.format( "api %s not wrappable as %s; context: %s, views: %s", apiMetadata, viewType, apiMetadata.getContext(), apiMetadata.getViews())); } return (V) buildInjector().getInstance(Key.get(TypeLiteral.get(returnType.getType()))); }
/** * looks up a provider or api with the given id * * @param providerOrApi * id of the provider or api * @return means to build a context to that provider * @throws NoSuchElementException * if the id was not configured. */ public static ContextBuilder newBuilder(String providerOrApi) throws NoSuchElementException { try { try { return ContextBuilder.newBuilder(Providers.withId(providerOrApi)); } catch (NoSuchElementException e) { return ContextBuilder.newBuilder(Apis.withId(providerOrApi)); } } catch (NoSuchElementException e) { Builder<String, String> builder = ImmutableMultimap.<String, String> builder(); builder.putAll("providers", transform(Providers.all(), Providers.idFunction())); builder.putAll("apis", transform(Apis.all(), Apis.idFunction())); throw new NoSuchElementException(String.format("key [%s] not in the list of providers or apis: %s", providerOrApi, builder.build())); } }
@Override public int complete(String buffer, int cursor, List<String> candidates) { try { if (displayApisWithoutService) { for (ApiMetadata apiMetadata : Apis.viewableAs(TypeToken.of(ComputeServiceContext.class))) { delegate.getStrings().add(apiMetadata.getId()); } } else if (computeServices != null) { for (ComputeService computeService : computeServices) { String id = computeService.getContext().unwrap().getId(); if (Apis.withId(id) != null) { delegate.getStrings().add(computeService.getContext().unwrap().getId()); } } } } catch (Exception ex) { // noop } return delegate.complete(buffer, cursor, candidates); }
@Override protected Object doExecute() throws Exception { try { System.out.println("BlobStore APIs:"); System.out.println("---------------"); printBlobStoreApis(Apis.viewableAs(TypeToken.of(BlobStoreContext.class)), getBlobStoreServices(), "", System.out); System.out.println(); System.out.println(); System.out.println("BlobStore Providers:"); System.out.println("--------------------"); printBlobStoreProviders(Providers.viewableAs(TypeToken.of(BlobStoreContext.class)), getBlobStoreServices(), "", System.out); } catch (Exception ex) { // noop } return null; } }
/** * Returns all available apis. * * @return all available apis */ public static Iterable<ApiMetadata> all() { return ImmutableSet.<ApiMetadata>builder() .addAll(fromServiceLoader()) .addAll(ApiRegistry.fromRegistry()).build(); }
/** * this will build any {@link ApiMetadata#getViews() view} supported by the ApiMetadata. * * ex. {@code builder.build(BlobStoreContext.class) } will work, if {@code TypeToken<BlobStore>} * is a configured {@link ApiMetadata#getViews() view} of this api. * */ @SuppressWarnings("unchecked") public <V extends View> V buildView(TypeToken<V> viewType) { TypeToken<V> returnType; try { returnType = (TypeToken<V>) Apis.findView(apiMetadata, checkNotNull(viewType, "viewType")); } catch (NoSuchElementException e) { throw new IllegalArgumentException(String.format( "api %s not wrappable as %s; context: %s, views: %s", apiMetadata, viewType, apiMetadata.getContext(), apiMetadata.getViews())); } return (V) buildInjector().getInstance(Key.get(TypeLiteral.get(returnType.getType()))); }
/** * looks up a provider or api with the given id * * @param providerOrApi * id of the provider or api * @return means to build a context to that provider * @throws NoSuchElementException * if the id was not configured. */ public static ContextBuilder newBuilder(String providerOrApi) throws NoSuchElementException { try { try { return ContextBuilder.newBuilder(Providers.withId(providerOrApi)); } catch (NoSuchElementException e) { return ContextBuilder.newBuilder(Apis.withId(providerOrApi)); } } catch (NoSuchElementException e) { Builder<String, String> builder = ImmutableMultimap.<String, String> builder(); builder.putAll("providers", transform(Providers.all(), Providers.idFunction())); builder.putAll("apis", transform(Apis.all(), Apis.idFunction())); throw new NoSuchElementException(String.format("key [%s] not in the list of providers or apis: %s", providerOrApi, builder.build())); } }
/** * @see org.jclouds.apis.Apis#withId */ protected ApiMetadata createApiMetadata() { try { return Apis.withId(provider); } catch (NoSuchElementException e) { return null; } }
/** * Returns all apis who's contexts are assignable from the parameter * * @param type * the type of the context to search for * * @return the apis with contexts assignable from given type */ public static Iterable<ApiMetadata> contextAssignableFrom(TypeToken<?> type) { return filter(all(), ApiPredicates.contextAssignableFrom(type)); }
private ImmutableSortedSet<String> getAllProviders() { // correct the classloader so that extensions can be found Thread.currentThread().setContextClassLoader(Apis.class.getClassLoader()); // TODO: apis need endpoints, providers don't; do something smarter // with this stuff :) Builder<String> builder = ImmutableSet.<String> builder(); builder.addAll(Iterables.transform(Apis.viewableAs(BlobStoreContext.class), Apis.idFunction())); builder.addAll(Iterables.transform(Providers.viewableAs(BlobStoreContext.class), Providers.idFunction())); return ImmutableSortedSet.copyOf(builder.build()); }
@Override protected Object doExecute() throws Exception { try { System.out.println("Compute APIs:"); System.out.println("-------------"); printComputeApis(Apis.viewableAs(TypeToken.of(ComputeServiceContext.class)), getComputeServices(), "", System.out); System.out.println(); System.out.println(); System.out.println("Compute Providers:"); System.out.println("------------------"); printComputeProviders(Providers.viewableAs(TypeToken.of(ComputeServiceContext.class)), getComputeServices(), "", System.out); } catch (Exception ex) { // noop } return null; } }
/** * Returns all available apis. * * @return all available apis */ public static Iterable<ApiMetadata> all() { return ImmutableSet.<ApiMetadata>builder() .addAll(fromServiceLoader()) .addAll(ApiRegistry.fromRegistry()).build(); }
/** * this will build any {@link ApiMetadata#getViews() view} supported by the ApiMetadata. * * ex. {@code builder.build(BlobStoreContext.class) } will work, if {@code TypeToken<BlobStore>} * is a configured {@link ApiMetadata#getViews() view} of this api. * */ @SuppressWarnings("unchecked") public <V extends View> V buildView(TypeToken<V> viewType) { TypeToken<V> returnType; try { returnType = (TypeToken<V>) Apis.findView(apiMetadata, checkNotNull(viewType, "viewType")); } catch (NoSuchElementException e) { throw new IllegalArgumentException(String.format( "api %s not wrappable as %s; context: %s, views: %s", apiMetadata, viewType, apiMetadata.getContext(), apiMetadata.getViews())); } return (V) buildInjector().getInstance(Key.get(TypeLiteral.get(returnType.getType()))); }