public Ec2Context(Ec2Credentials credentials) { this.credentials = credentials; Properties properties = new Properties(); long scriptTimeout = TimeUnit.MILLISECONDS.convert(50, TimeUnit.MINUTES); properties.setProperty(TIMEOUT_SCRIPT_COMPLETE, scriptTimeout + ""); properties.setProperty(TIMEOUT_PORT_OPEN, scriptTimeout + ""); properties.setProperty(PROPERTY_CONNECTION_TIMEOUT, scriptTimeout + ""); properties.setProperty( PROPERTY_EC2_AMI_QUERY, "owner-id=137112412989;state=available;image-type=machine"); properties.setProperty(PROPERTY_EC2_CC_AMI_QUERY, ""); properties.setProperty( Constants.PROPERTY_MAX_RETRIES, Settings.JCLOUDS_PROPERTY_MAX_RETRIES + ""); properties.setProperty( Constants.PROPERTY_RETRY_DELAY_START, Settings.JCLOUDS_PROPERTY_RETRY_DELAY_START + ""); Iterable<Module> modules = ImmutableSet.<Module>of( new SshjSshClientModule(), new SLF4JLoggingModule(), new EnterpriseConfigurationModule()); ContextBuilder build = ContextBuilder.newBuilder("aws-ec2") .credentials(credentials.getAccessKey(), credentials.getSecretKey()) .modules(modules) .overrides(properties); ComputeServiceContext context = build.buildView(ComputeServiceContext.class); this.computeService = (AWSEC2ComputeService) context.getComputeService(); this.ec2api = computeService.getContext().unwrapApi(EC2Api.class); this.securityGroupApi = ec2api.getSecurityGroupApi().get(); this.keypairApi = (AWSKeyPairApi) ec2api.getKeyPairApi().get(); vmBatchSize = Settings.AWS_VM_BATCH_SIZE(); }
@Before public void setUp() { Properties prop = new Properties(); prop.put(Constants.PROPERTY_ENDPOINT, TestConstants.ENDPOINT); ContextBuilder builder = ContextBuilder.newBuilder(TestConstants.PROVIDER) .credentials(TestConstants.API_KEY, TestConstants.SECRET_KEY) // .modules(modules) .overrides(prop); CloudStackContext context = builder.buildView(CloudStackContext.class); RestContext<CloudStackClient, CloudStackAsyncClient> providerContext = context.getProviderSpecificContext(); client = providerContext.getApi(); }
/** * Temporary constructor to address https://issues.apache.org/jira/browse/JCLOUDS-615. * * <p>See https://issues.apache.org/jira/browse/BROOKLYN-6 . When * https://issues.apache.org/jira/browse/JCLOUDS-615 is fixed in the jclouds we use, we can remove * the useSoftlayerFix argument. * * <p>(Marked Beta as that argument will likely be removed.) * * @since 0.7.0 */ @Beta public static BlobStoreContext newBlobstoreContext( String provider, @Nullable String endpoint, String identity, String credential) { Properties overrides = new Properties(); // * Java 7,8 bug workaround - sockets closed by GC break the internal bookkeeping // of HttpUrlConnection, leading to invalid handling of the "HTTP/1.1 100 Continue" // response. Coupled with a bug when using SSL sockets reads will block // indefinitely even though a read timeout is explicitly set. // * Java 6 ignores the header anyways as it is included in its restricted headers black list. // * Also there's a bug in SL object store which still expects Content-Length bytes // even when it responds with a 408 timeout response, leading to incorrectly // interpreting the next request (triggered by above problem). overrides.setProperty(Constants.PROPERTY_STRIP_EXPECT_HEADER, "true"); ContextBuilder contextBuilder = ContextBuilder.newBuilder(provider).credentials(identity, credential); contextBuilder.modules(MutableList.copyOf(JcloudsUtil.getCommonModules())); if (!org.apache.brooklyn.util.text.Strings.isBlank(endpoint)) { contextBuilder.endpoint(endpoint); } contextBuilder.overrides(overrides); BlobStoreContext context = contextBuilder.buildView(BlobStoreContext.class); return context; }