public T fromApiMetadata(ApiMetadata in) { return id(in.getId()).views(in.getViews()).name(in.getName()).endpointName(in.getEndpointName()).identityName( in.getIdentityName()).credentialName(in.getCredentialName().orNull()).version(in.getVersion()) .buildVersion(in.getBuildVersion().orNull()).defaultEndpoint(in.getDefaultEndpoint().orNull()) .defaultIdentity(in.getDefaultIdentity().orNull()).defaultCredential( in.getDefaultCredential().orNull()).defaultProperties(in.getDefaultProperties()) .documentation(in.getDocumentation()).context(in.getContext()).defaultModules(in.getDefaultModules()); } }
public void listBlobstoreApis(Iterable<ApiMetadata> blobstoreApis, PrintStream out) { for(ApiMetadata blobstore : blobstoreApis) { out.println("* " + blobstore.getName()); out.println("\tAPI: " + blobstore.getDocumentation()); out.println("\tConfiguration options:"); out.println("\t\twhirr.blobstore-provider = " + blobstore.getId()); out.println("\t\twhirr.blobstore-endpoint = " + blobstore.getEndpointName()); out.println("\t\twhirr.blobstore-identity = <" + blobstore.getIdentityName() +">"); out.println("\t\twhirr.blobstore-credential = <" + blobstore.getCredentialName().or("UNUSED") + ">\n"); } }
protected ContextBuilder(@Nullable ProviderMetadata providerMetadata, ApiMetadata apiMetadata) { this.apiMetadata = checkNotNull(apiMetadata, "apiMetadata"); if (providerMetadata != null) { this.providerMetadata = Optional.of(providerMetadata); this.endpoint = Optional.of(providerMetadata.getEndpoint()); this.providerId = providerMetadata.getId(); } else { this.endpoint = apiMetadata.getDefaultEndpoint(); this.providerId = apiMetadata.getId(); } this.identity = apiMetadata.getDefaultIdentity(); this.credential = apiMetadata.getDefaultCredential().orNull(); this.apiVersion = apiMetadata.getVersion(); this.buildVersion = apiMetadata.getBuildVersion().or(""); }
@Override protected void configure() { bind(ProviderMetadata.class).toInstance(providerMetadata); Properties toBind = new Properties(); toBind.putAll(providerMetadata.getApiMetadata().getDefaultProperties()); toBind.putAll(providerMetadata.getDefaultProperties()); Names.bindProperties(binder(), toBind); bind(new TypeLiteral<Supplier<Credentials>>(){}).annotatedWith(Provider.class).toInstance(creds); bindConstant().annotatedWith(Provider.class).to(providerMetadata.getId()); bind(new TypeLiteral<Set<String>>() { }).annotatedWith(Iso3166.class).toInstance(providerMetadata.getIso3166Codes()); bindConstant().annotatedWith(Api.class).to(providerMetadata.getApiMetadata().getId()); bindConstant().annotatedWith(ApiVersion.class).to(providerMetadata.getApiMetadata().getVersion()); // nullable bind(String.class).annotatedWith(BuildVersion.class).toProvider( com.google.inject.util.Providers.of(providerMetadata.getApiMetadata().getBuildVersion().orNull())); bind(new TypeLiteral<TypeToken<? extends Context>>() { }).annotatedWith(Provider.class).toInstance(providerMetadata.getApiMetadata().getContext()); }
@Override public boolean equals(Object o) { if (this == o) return true; // subclass equivalence is ok, since we don't know the classloader // we'll get things from if (o == null || !(o instanceof ApiMetadata)) return false; ApiMetadata that = ApiMetadata.class.cast(o); return equal(this.getId(), that.getId()) && equal(this.getName(), that.getName()) && equal(this.getViews(), that.getViews()); }
private Properties currentStateToUnexpandedProperties() { Properties defaults = new Properties(); defaults.putAll(apiMetadata.getDefaultProperties()); defaults.setProperty(PROPERTY_PROVIDER,providerId); if (providerMetadata.isPresent()) { defaults.putAll(providerMetadata.get().getDefaultProperties()); defaults.setProperty(PROPERTY_ISO3166_CODES, Joiner.on(',').join(providerMetadata.get().getIso3166Codes())); } if (endpoint.isPresent()) defaults.setProperty(PROPERTY_ENDPOINT, endpoint.get()); defaults.setProperty(PROPERTY_API, apiMetadata.getName()); defaults.setProperty(PROPERTY_API_VERSION, apiVersion); defaults.setProperty(PROPERTY_BUILD_VERSION, buildVersion); if (identity.isPresent()) defaults.setProperty(PROPERTY_IDENTITY, identity.get()); if (credential != null) defaults.setProperty(PROPERTY_CREDENTIAL, credential); if (overrides.isPresent()) defaults.putAll(checkNotNull(overrides.get(), "overrides")); defaults.putAll(propertiesPrefixedWithJcloudsApiOrProviderId(getSystemProperties(), apiMetadata.getId(), providerId)); return defaults; }
public ProviderMetadata apply(@Nullable org.jclouds.providers.ProviderMetadata input) { if (input == null) { return null; } return ProviderMetadata.builder().id(input.getId()).name(input.getName()) .endpoint(input.getEndpoint()) .console(input.getConsole().orNull()).homePage(input.getHomepage().orNull()) .linkedServices(input.getLinkedServices()).iso3166Codes(input.getIso3166Codes()) .identityName(input.getApiMetadata().getIdentityName()) .credentialName(input.getApiMetadata().getCredentialName().orNull()) .endpointName(input.getApiMetadata().getEndpointName()) .documentation(input.getApiMetadata().getDocumentation().toString()) .defaultProperties(fromProperties(input.getApiMetadata().getDefaultProperties(), input.getDefaultProperties())) .defaultModules(ImmutableSet.<String>builder().addAll(transform(input.getApiMetadata().getDefaultModules(), new Function<Class<? extends Module>, String>() { @Override public String apply(@Nullable Class<? extends Module> input) { return input.getName(); } })).build()) .views(ImmutableSet.<String>builder().addAll(transform(input.getApiMetadata().getViews(), new Function<TypeToken<? extends View>, String>() { @Override public String apply(@Nullable TypeToken<? extends View> input) { return input.getRawType().getName(); } })).build()) .build(); }
public void listBlobstoreProviders(Iterable<ProviderMetadata> blobstoreProviders, PrintStream out) { for(ProviderMetadata blobstore : blobstoreProviders) { out.println("* " + blobstore.getName()); out.println("\tHomepage: " + blobstore.getHomepage()); out.println("\tConsole: " + blobstore.getConsole()); out.println("\tAPI: " + blobstore.getApiMetadata().getDocumentation()); out.println("\tConfiguration options:"); out.println("\t\twhirr.blobstore-provider = " + blobstore.getId()); out.println("\t\twhirr.blobstore-identity = <" + blobstore.getApiMetadata().getIdentityName() +">"); out.println("\t\twhirr.blobstore-credential = <" + blobstore.getApiMetadata().getCredentialName().or("UNUSED") + ">\n"); } }
@Override public String apply(ApiMetadata input) { return input.getId(); }
public static ChefService createChefService(ApiMetadata apiMetadata, String name, String clientName, String clientCredential, String clientKeyFile, String validatorName, String validatorCredential, String validatorKeyFile, String endpoint) throws Exception { if (Strings.isNullOrEmpty(clientName) && apiMetadata != null && !apiMetadata.getDefaultCredential().isPresent()) { LOGGER.warn("No client specified for api {}.", apiMetadata.getId()); return null; if (Strings.isNullOrEmpty(validatorName) && apiMetadata != null && !apiMetadata.getDefaultCredential().isPresent()) { LOGGER.warn("No validator name specified for api {}.", apiMetadata.getId()); return null;
/** * {@inheritDoc} */ @Override public Map<String, Object> getMetadata() { return ImmutableMap.<String, Object> of("endpoint", URI.create(providerMetadata.getEndpoint()), "apiVersion", providerMetadata.getApiMetadata().getVersion(), "buildVersion", providerMetadata.getApiMetadata() .getBuildVersion().or(""), "identity", getIdentity()); }
/** * Checks if configuration is valid for the specified {@link ApiMetadata} * * @param apiMetadata * @param properties * @throws InvalidConfigurationException */ public static void validate(ApiMetadata apiMetadata, Dictionary properties) throws InvalidConfigurationException { if (Strings.isNullOrEmpty((String) properties.get(Constants.IDENTITY)) && !apiMetadata.getDefaultIdentity().isPresent()) { throw new InvalidConfigurationException("No identity specified."); } if (Strings.isNullOrEmpty((String) properties.get(Constants.CREDENTIAL)) && !apiMetadata.getDefaultCredential().isPresent()) { throw new InvalidConfigurationException("No credential specified specified."); } if (Strings.isNullOrEmpty((String) properties.get(Constants.ENDPOINT)) && !apiMetadata.getDefaultEndpoint().isPresent()) { throw new InvalidConfigurationException("No credential specified specified."); } }
/** * Builds the base context for this api. Note that this may be of type {@link Closer}, if nothing * else was configured via {@link ApiMetadata#getContext()}. Typically, the type returned is * {@link RestContext} * * @see ApiMetadata#getContext() * @see #build(TypeToken) */ @SuppressWarnings("unchecked") public <C extends Context> C build() { return (C) build(apiMetadata.getContext()); }
/** * {@inheritDoc} */ @Override public Builder apiMetadata(ApiMetadata api) { this.api = checkNotNull(api, "api"); if (this.endpoint == null) this.endpoint = api.getDefaultEndpoint().orNull(); return this; }
/** * {@inheritDoc} */ @Override public boolean apply(ApiMetadata apiMetadata) { for (TypeToken<? extends View> to : apiMetadata.getViews()) if (type.isAssignableFrom(to)) return true; return false; }
/** * 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()))); }
/** * Checks if configuration is valid for the specified {@link ProviderMetadata}. * * @param providerMetadata * @param properties * @throws InvalidConfigurationException * */ public static void validate(ProviderMetadata providerMetadata, Dictionary properties) throws InvalidConfigurationException { if (Strings.isNullOrEmpty((String) properties.get(Constants.IDENTITY)) && !providerMetadata.getApiMetadata().getDefaultIdentity().isPresent()) { throw new InvalidConfigurationException("No identity specified."); } if (Strings.isNullOrEmpty((String) properties.get(Constants.CREDENTIAL)) && !providerMetadata.getApiMetadata().getDefaultCredential().isPresent()) { throw new InvalidConfigurationException("No credential specified specified."); } }
@Inject UseApiToResolveProjectName(GetProject api, @Provider Supplier<URI> defaultEndpoint, ProviderMetadata metadata) { this.api = api; this.defaultEndpoint = defaultEndpoint; this.identityName = metadata.getApiMetadata().getIdentityName(); }
@Test public void testAll() { Iterable<ApiMetadata> apisMetadata = Apis.all(); for (ApiMetadata apiMetadata : apisMetadata) { if (apiMetadata.getName().equals(testBlobstoreApi.getName())) { assertEquals(testBlobstoreApi, apiMetadata); } else if (apiMetadata.getName().equals(testComputeApi.getName())) { assertEquals(testComputeApi, apiMetadata); } else { assertEquals(testYetAnotherComputeApi, apiMetadata); } } }