org.jclouds.domain.Location Java Examples
The following examples show how to use
org.jclouds.domain.Location.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JcloudsLocationSecurityGroupCustomizer.java From brooklyn-server with Apache License 2.0 | 6 votes |
/** * Loads the security group to be shared between nodes in the same application in the * given Location. If no such security group exists it is created. * * @param location The location in which the security group will be found * @param securityApi The API to use to list and create security groups * @return the security group to share between instances in the given location in this application */ private SecurityGroup getOrCreateSharedSecurityGroup(Location location, SecurityGroupEditor groupEditor) { final String groupName = getNameForSharedSecurityGroup(); // Could sort-and-search if straight search is too expensive Optional<SecurityGroup> shared = groupEditor.findSecurityGroupByName(groupName); if (shared.isPresent()) { LOG.info("Found existing shared security group in {} for app {}: {}", new Object[]{location, applicationId, groupName}); return shared.get(); } else { LOG.info("Creating new shared security group in {} for app {}: {}", new Object[]{location, applicationId, groupName}); return createBaseSecurityGroupInLocation(groupName, groupEditor); } }
Example #2
Source File: JcloudsLocationSecurityGroupCustomizerTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testAddPermissionsToNode() { IpPermission ssh = newPermission(22); IpPermission jmx = newPermission(31001); SecurityGroup sharedGroup = newGroup(customizer.getNameForSharedSecurityGroup()); SecurityGroup group = newGroup("id"); when(securityApi.listSecurityGroupsForNode(NODE_ID)).thenReturn(ImmutableSet.of(sharedGroup, group)); SecurityGroup updatedSecurityGroup = newGroup("id", ImmutableSet.of(ssh, jmx)); when(securityApi.addIpPermission(ssh, group)).thenReturn(updatedSecurityGroup); when(securityApi.addIpPermission(jmx, group)).thenReturn(updatedSecurityGroup); when(computeService.getContext().unwrap().getId()).thenReturn("aws-ec2"); customizer.addPermissionsToLocation(jcloudsMachineLocation, ImmutableList.of(ssh, jmx)); verify(securityApi, never()).createSecurityGroup(anyString(), any(Location.class)); verify(securityApi, times(1)).addIpPermission(ssh, group); verify(securityApi, times(1)).addIpPermission(jmx, group); }
Example #3
Source File: JcloudsLocationSecurityGroupCustomizerTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testSharedGroupLoadedWhenItExistsButIsNotCached() { Template template = mock(Template.class); TemplateOptions templateOptions = mock(TemplateOptions.class); when(template.getLocation()).thenReturn(location); when(template.getOptions()).thenReturn(templateOptions); JcloudsLocation jcloudsLocation = new JcloudsLocation(MutableMap.of("deferConstruction", true)); SecurityGroup shared = newGroup(customizer.getNameForSharedSecurityGroup()); SecurityGroup irrelevant = newGroup("irrelevant"); when(securityApi.createSecurityGroup(shared.getName(), location)).thenReturn(shared); when(securityApi.createSecurityGroup(irrelevant.getName(), location)).thenReturn(irrelevant); when(securityApi.listSecurityGroupsInLocation(location)).thenReturn(ImmutableSet.of(irrelevant, shared)); when(securityApi.addIpPermission(any(IpPermission.class), eq(shared))).thenReturn(shared); when(securityApi.addIpPermission(any(IpPermission.class), eq(irrelevant))).thenReturn(irrelevant); customizer.customize(jcloudsLocation, computeService, template); verify(securityApi).listSecurityGroupsInLocation(location); verify(securityApi, never()).createSecurityGroup(anyString(), any(Location.class)); }
Example #4
Source File: JcloudsRateLimitedRetryLiveTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
private void testSecurityEditorOnMachine(int n, final JcloudsSshMachineLocation machine) throws ExecutionException, InterruptedException { final Location location = machine.getNode().getLocation(); ComputeService computeService = machine.getParent().getComputeService(); final Optional<SecurityGroupExtension> securityApi = computeService.getSecurityGroupExtension(); final SecurityGroupEditor editor = new SecurityGroupEditor(location, securityApi.get()); List<ListenableFuture<?>> futures = Lists.newArrayList(); for (int c = 0; c < n; c++) { final String id = "sgtest-" + Identifiers.makeRandomLowercaseId(6) + "-" + String.valueOf(c); final Runnable task = new Runnable() { @Override public void run() { doOneSecurityEditorOperationCycle(id, editor, machine); } }; ListenableFuture<?> future = executor.submit(task); futures.add(future); } assertTasksDoneSuccessfully(futures); }
Example #5
Source File: JcloudsPredicates.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Override public boolean apply(ComputeMetadata input) { boolean exclude; Location nodeLocation = input.getLocation(); if (nodeLocation==null) return matchNullLocations; exclude = true; while (nodeLocation!=null && exclude) { if (nodeLocation.getId().equals(regionId)) { // matching location info found exclude = false; } nodeLocation = nodeLocation.getParent(); } return !exclude; }
Example #6
Source File: JcloudsLocationSecurityGroupCustomizerTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testAddRuleNotRetriedByDefault() { IpPermission ssh = newPermission(22); SecurityGroup sharedGroup = newGroup(customizer.getNameForSharedSecurityGroup()); SecurityGroup uniqueGroup = newGroup("unique"); when(securityApi.listSecurityGroupsForNode(NODE_ID)).thenReturn(ImmutableSet.of(sharedGroup, uniqueGroup)); when(securityApi.addIpPermission(eq(ssh), eq(uniqueGroup))) .thenThrow(new RuntimeException("exception creating " + ssh)); when(computeService.getContext().unwrap().getId()).thenReturn("aws-ec2"); try { customizer.addPermissionsToLocation(jcloudsMachineLocation, ImmutableList.of(ssh)); } catch (Exception e) { assertTrue(e.getMessage().contains("repeated errors from provider"), "message=" + e.getMessage()); } verify(securityApi, never()).createSecurityGroup(anyString(), any(Location.class)); verify(securityApi, times(1)).addIpPermission(ssh, uniqueGroup); }
Example #7
Source File: JcloudsLocationSecurityGroupCustomizerTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testAddRuleRetriedOnAwsFailure() { IpPermission ssh = newPermission(22); SecurityGroup sharedGroup = newGroup(customizer.getNameForSharedSecurityGroup()); SecurityGroup uniqueGroup = newGroup("unique"); customizer.setRetryExceptionPredicate(JcloudsLocationSecurityGroupCustomizer.newAwsExceptionRetryPredicate()); when(securityApi.listSecurityGroupsForNode(NODE_ID)).thenReturn(ImmutableSet.of(sharedGroup, uniqueGroup)); when(securityApi.addIpPermission(any(IpPermission.class), eq(uniqueGroup))) .thenThrow(newAwsResponseExceptionWithCode("InvalidGroup.InUse")) .thenThrow(newAwsResponseExceptionWithCode("DependencyViolation")) .thenThrow(newAwsResponseExceptionWithCode("RequestLimitExceeded")) .thenThrow(newAwsResponseExceptionWithCode("Blocked")) .thenReturn(sharedGroup); when(computeService.getContext().unwrap().getId()).thenReturn("aws-ec2"); try { customizer.addPermissionsToLocation(jcloudsMachineLocation, ImmutableList.of(ssh)); } catch (Exception e) { String expected = "repeated errors from provider"; assertTrue(e.getMessage().contains(expected), "expected exception message to contain " + expected + ", was: " + e.getMessage()); } verify(securityApi, never()).createSecurityGroup(anyString(), any(Location.class)); verify(securityApi, times(4)).addIpPermission(ssh, uniqueGroup); }
Example #8
Source File: AreWeConsistentYetTest.java From are-we-consistent-yet with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { ContextBuilder builder = ContextBuilder .newBuilder("transient") .credentials("identity", "credential") .modules(ImmutableList.<Module>of(new SLF4JLoggingModule())); context = builder.build(BlobStoreContext.class); contextRead = builder.build(BlobStoreContext.class); BlobStore blobStore = context.getBlobStore(); BlobStore blobStoreRead = contextRead.getBlobStore(); String containerName = "container-name"; Location location = null; blobStore.createContainerInLocation(location, containerName); blobStoreRead.createContainerInLocation(location, containerName); awcyStrong = new AreWeConsistentYet(blobStore, blobStore, containerName, ITERATIONS, OBJECT_SIZE); awcyEventual = new AreWeConsistentYet(blobStore, blobStoreRead, containerName, ITERATIONS, OBJECT_SIZE); }
Example #9
Source File: AWSEC2ComputeService.java From attic-stratos with Apache License 2.0 | 5 votes |
@Inject protected AWSEC2ComputeService(ComputeServiceContext context, Map<String, Credentials> credentialStore, @Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> sizes, @Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy, GetImageStrategy getImageStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy, CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy, RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy, ResumeNodeStrategy startNodeStrategy, SuspendNodeStrategy stopNodeStrategy, Provider<TemplateBuilder> templateBuilderProvider, @Named("DEFAULT") Provider<TemplateOptions> templateOptionsProvider, @Named(TIMEOUT_NODE_RUNNING) Predicate<AtomicReference<NodeMetadata>> nodeRunning, @Named(TIMEOUT_NODE_TERMINATED) Predicate<AtomicReference<NodeMetadata>> nodeTerminated, @Named(TIMEOUT_NODE_SUSPENDED) Predicate<AtomicReference<NodeMetadata>> nodeSuspended, InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory, RunScriptOnNode.Factory runScriptOnNodeFactory, InitAdminAccess initAdminAccess, PersistNodeCredentials persistNodeCredentials, Timeouts timeouts, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, AWSEC2Api client, ConcurrentMap<RegionAndName, KeyPair> credentialsMap, @Named("SECURITY") LoadingCache<RegionAndName, String> securityGroupMap, @Named("PLACEMENT") LoadingCache<RegionAndName, String> placementGroupMap, @Named("DELETED") Predicate<PlacementGroup> placementGroupDeleted, Optional<ImageExtension> imageExtension, GroupNamingConvention.Factory namingConvention, @Named(PROPERTY_EC2_GENERATE_INSTANCE_NAMES) boolean generateInstanceNames, Optional<SecurityGroupExtension> securityGroupExtension) { super(context, credentialStore, images, sizes, locations, listNodesStrategy, getImageStrategy, getNodeMetadataStrategy, runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, startNodeStrategy, stopNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning, nodeTerminated, nodeSuspended, initScriptRunnerFactory, runScriptOnNodeFactory, initAdminAccess, persistNodeCredentials, timeouts, userExecutor, client, credentialsMap, securityGroupMap, imageExtension, namingConvention, generateInstanceNames, securityGroupExtension); this.client = client; this.placementGroupMap = placementGroupMap; this.placementGroupDeleted = placementGroupDeleted; }
Example #10
Source File: AWSRunningInstanceToNodeMetadata.java From attic-stratos with Apache License 2.0 | 5 votes |
@Inject protected AWSRunningInstanceToNodeMetadata(Map<InstanceState, Status> instanceToNodeStatus, Map<String, Credentials> credentialStore, Supplier<LoadingCache<RegionAndName, ? extends Image>> imageMap, @Memoized Supplier<Set<? extends Location>> locations, @Memoized Supplier<Set<? extends Hardware>> hardware, GroupNamingConvention.Factory namingConvention) { super(instanceToNodeStatus, credentialStore, imageMap, locations, hardware, namingConvention); }
Example #11
Source File: AWSEC2TemplateBuilderImpl.java From attic-stratos with Apache License 2.0 | 5 votes |
@Inject protected AWSEC2TemplateBuilderImpl(@Memoized Supplier<Set<? extends Location>> locations, ImageCacheSupplier images, @Memoized Supplier<Set<? extends Hardware>> sizes, Supplier<Location> defaultLocation, @Named("DEFAULT") Provider<TemplateOptions> optionsProvider, @Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider, GetImageStrategy getImageStrategy, Supplier<LoadingCache<RegionAndName, ? extends Image>> imageMap) { super(locations, images, sizes, defaultLocation, optionsProvider, defaultTemplateProvider, getImageStrategy, imageMap); }
Example #12
Source File: SharedLocationSecurityGroupCustomizerTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@BeforeMethod(alwaysRun = true) public void setUp() { sgCustomizer = mock(JcloudsLocationSecurityGroupCustomizer.class); customizer = new TestSharedLocationSecurityGroupCustomizer(); location = mock(Location.class); securityApi = mock(SecurityGroupExtension.class); computeService = mock(ComputeService.class, Answers.RETURNS_DEEP_STUBS.get()); mockTemplate = mock(Template.class); mockOptions = mock(TemplateOptions.class); when(computeService.getSecurityGroupExtension()).thenReturn(Optional.of(securityApi)); when(mockTemplate.getOptions()).thenReturn(mockOptions); when(mockOptions.getInboundPorts()).thenReturn(new int[]{}); }
Example #13
Source File: AWSEC2SecurityGroupExtension.java From attic-stratos with Apache License 2.0 | 5 votes |
@Inject public AWSEC2SecurityGroupExtension(AWSEC2Api client, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, @Region Supplier<Set<String>> regions, Function<org.jclouds.ec2.domain.SecurityGroup, SecurityGroup> groupConverter, @Memoized Supplier<Set<? extends Location>> locations, @Named("SECURITY") LoadingCache<RegionAndName, String> groupCreator, GroupNamingConvention.Factory namingConvention, @Named("SECGROUP_NAME_TO_ID") Function<String, String> groupNameToId) { super(client, userExecutor, regions, groupConverter, locations, groupCreator, namingConvention); this.client = checkNotNull(client, "client"); this.groupNameToId = checkNotNull(groupNameToId, "groupNameToId"); }
Example #14
Source File: EventualBlobStore.java From s3proxy with Apache License 2.0 | 5 votes |
@Override public boolean createContainerInLocation(Location location, String container, CreateContainerOptions options) { return delegate().createContainerInLocation( location, container, options) && writeStore.createContainerInLocation( location, container, options); }
Example #15
Source File: AWSEC2ImageParserTest.java From attic-stratos with Apache License 2.0 | 5 votes |
public static Set<org.jclouds.compute.domain.Image> convertImages(String resource) { Map<OsFamily, Map<String, String>> map = new BaseComputeServiceContextModule() { }.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule()) .getInstance(Json.class)); Set<Image> result = DescribeImagesResponseHandlerTest.parseImages(resource); EC2ImageParser parser = new EC2ImageParser(EC2ComputeServiceDependenciesModule.toPortableImageStatus, new EC2PopulateDefaultLoginCredentialsForImageStrategy(), map, Suppliers .<Set<? extends Location>> ofInstance(ImmutableSet.<Location> of(defaultLocation)), Suppliers .ofInstance(defaultLocation), new AWSEC2ReviseParsedImage(map)); return Sets.newLinkedHashSet(Iterables.filter(Iterables.transform(result, parser), Predicates.notNull())); }
Example #16
Source File: JcloudsLocationSecurityGroupCustomizerTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test public void testCustomExceptionRetryablePredicate() { final String message = "testCustomExceptionRetryablePredicate"; Predicate<Exception> messageChecker = new Predicate<Exception>() { @Override public boolean apply(Exception input) { Throwable t = input; while (t != null) { if (t.getMessage().contains(message)) { return true; } else { t = t.getCause(); } } return false; } }; customizer.setRetryExceptionPredicate(messageChecker); when(computeService.getContext().unwrap().getId()).thenReturn("aws-ec2"); IpPermission ssh = newPermission(22); SecurityGroup sharedGroup = newGroup(customizer.getNameForSharedSecurityGroup()); SecurityGroup uniqueGroup = newGroup("unique"); when(securityApi.listSecurityGroupsForNode(NODE_ID)).thenReturn(ImmutableSet.of(sharedGroup, uniqueGroup)); when(securityApi.addIpPermission(eq(ssh), eq(uniqueGroup))) .thenThrow(new RuntimeException(new Exception(message))) .thenThrow(new RuntimeException(new Exception(message))) .thenReturn(sharedGroup); customizer.addPermissionsToLocation(jcloudsMachineLocation, ImmutableList.of(ssh)); verify(securityApi, never()).createSecurityGroup(anyString(), any(Location.class)); verify(securityApi, times(3)).addIpPermission(ssh, uniqueGroup); }
Example #17
Source File: AWSRunningInstanceToNodeMetadataTest.java From attic-stratos with Apache License 2.0 | 5 votes |
private AWSRunningInstanceToNodeMetadata createNodeParser(final ImmutableSet<Hardware> hardware, final ImmutableSet<Location> locations, Map<String, Credentials> credentialStore, Map<InstanceState, Status> instanceToNodeStatus, LoadingCache<RegionAndName, ? extends Image> instanceToImage) { Supplier<Set<? extends Location>> locationSupplier = new Supplier<Set<? extends Location>>() { @Override public Set<? extends Location> get() { return locations; } }; Supplier<Set<? extends Hardware>> hardwareSupplier = new Supplier<Set<? extends Hardware>>() { @Override public Set<? extends Hardware> get() { return hardware; } }; GroupNamingConvention.Factory namingConvention = Guice.createInjector(new AbstractModule() { @Override protected void configure() { Names.bindProperties(binder(), new AWSEC2ApiMetadata().getDefaultProperties()); } }).getInstance(GroupNamingConvention.Factory.class); AWSRunningInstanceToNodeMetadata parser = new AWSRunningInstanceToNodeMetadata(instanceToNodeStatus, credentialStore, Suppliers.<LoadingCache<RegionAndName, ? extends Image>> ofInstance(instanceToImage), locationSupplier, hardwareSupplier, namingConvention); return parser; }
Example #18
Source File: AWSEC2SecurityGroupToSecurityGroupTest.java From attic-stratos with Apache License 2.0 | 5 votes |
private AWSEC2SecurityGroupToSecurityGroup createGroupParser(final ImmutableSet<Location> locations) { Supplier<Set<? extends Location>> locationSupplier = new Supplier<Set<? extends Location>>() { @Override public Set<? extends Location> get() { return locations; } }; AWSEC2SecurityGroupToSecurityGroup parser = new AWSEC2SecurityGroupToSecurityGroup(locationSupplier); return parser; }
Example #19
Source File: GenerateTempURL.java From jclouds-examples with Apache License 2.0 | 5 votes |
private void createContainer() throws IOException { // Ensure that the container exists Location location = new LocationBuilder().scope(LocationScope.REGION).id(REGION).description("region").build(); if (!blobStore.containerExists(CONTAINER)) { blobStore.createContainerInLocation(location, CONTAINER); System.out.format("Created container in %s%n", REGION); } }
Example #20
Source File: UploadDirectoryToCDN.java From jclouds-examples with Apache License 2.0 | 5 votes |
/** * Generate a list of all of the local files under the specified dirPath and then upload them to container. */ private void uploadDirectory(String dirPath, String container) throws InterruptedException, ExecutionException { File dir = new File(dirPath); checkArgument(dir.isDirectory(), "%s is not a directory", dirPath); System.out.format("Uploading %s to %s", dirPath, container); // There is only one assignable location because we are using the RegionScopedBlobStoreContext Location location = getOnlyElement(blobStore.listAssignableLocations()); blobStore.createContainerInLocation(location, container); List<BlobDetail> blobDetails = Lists.newArrayList(); generateFileList(dir, "", blobDetails); uploadFiles(container, blobDetails); }
Example #21
Source File: AliOSSBlobStoreTest.java From multiapps-controller with Apache License 2.0 | 5 votes |
@Before public void init() { AliOSSApi aliOSSApi = Mockito.mock(AliOSSApi.class); ossClient = Mockito.spy(OSS.class); Mockito.when(aliOSSApi.getOSSClient()).thenReturn(ossClient); context = Mockito.mock(BlobStoreContext.class); blobUtils = Mockito.mock(BlobUtils.class); PayloadSlicer slicer = new BasePayloadSlicer(); LocationsSupplier locations = () -> Sets.newHashSet(LOCATION); Supplier<Location> defaultLocation = () -> LOCATION; aliOSSBlobStore = new AliOSSBlobStore(aliOSSApi, context, blobUtils, defaultLocation, locations, slicer); }
Example #22
Source File: JCloudsAppStorageService.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static Location createRegionLocation( BlobStoreProperties config, Location provider ) { return config.location != null ? new LocationBuilder() .scope( LocationScope.REGION ) .id( config.location ) .description( config.location ) .parent( provider ) .build() : null; }
Example #23
Source File: JCloudsFileResourceContentStore.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static Location createRegionLocation( BlobStoreProperties config, Location provider ) { return config.location != null ? new LocationBuilder() .scope( LocationScope.REGION ) .id( config.location ) .description( config.location ) .parent( provider ) .build() : null; }
Example #24
Source File: ObjectStorageBlobStoreTest.java From james-project with Apache License 2.0 | 5 votes |
@Test void deleteAllBucketsShouldDeleteAllContainersInBlobStore() { Location defaultLocation = null; blobStore.createContainerInLocation(defaultLocation, "bucket1"); blobStore.createContainerInLocation(defaultLocation, "bucket2"); blobStore.createContainerInLocation(defaultLocation, "bucket3"); objectStorageBlobStore.deleteAllBuckets().block(); assertThat(blobStore.list() .stream() .filter(storageMetadata -> storageMetadata.getType().equals(StorageType.CONTAINER))) .isEmpty(); }
Example #25
Source File: JcloudsLocationSecurityGroupCustomizer.java From brooklyn-server with Apache License 2.0 | 5 votes |
/** * Applies the given security group permissions to the given node with the given compute service. * <p> * Takes no action if the compute service does not have a security group extension. * @param permissions The set of permissions to be applied to the node * @param location */ private Map<String, SecurityGroup> addPermissionsInternal(Iterable<IpPermission> permissions, JcloudsMachineLocation location) { String nodeId = location.getNode().getId(); final Location nodeLocation = location.getNode().getLocation(); ComputeService computeService = location.getParent().getComputeService(); final Optional<SecurityGroupExtension> securityApi = computeService.getSecurityGroupExtension(); if (!securityApi.isPresent()) { LOG.warn("Security group extension for {} absent; cannot update node {} with {}", new Object[] {computeService, nodeId, permissions}); return ImmutableMap.of(); } final SecurityGroupEditor groupEditor = createSecurityGroupEditor(securityApi.get(), nodeLocation); // Expect to have two security groups on the node: one shared between all nodes in the location, // that is cached in sharedGroupCache, and one created by Jclouds that is unique to the node. // Relies on customize having been called before. This should be safe because the arguments // needed to call this method are not available until post-instance creation. String locationId = computeService.getContext().unwrap().getId(); SecurityGroup machineUniqueSecurityGroup = getMachineUniqueSecurityGroup(nodeId, locationId, groupEditor); MutableList<IpPermission> newPermissions = MutableList.copyOf(permissions); Iterables.removeAll(newPermissions, machineUniqueSecurityGroup.getIpPermissions()); machineUniqueSecurityGroup = groupEditor.addPermissions(machineUniqueSecurityGroup, newPermissions); return MutableMap.of(machineUniqueSecurityGroup.getId(), machineUniqueSecurityGroup); }
Example #26
Source File: AWSEC2SecurityGroupToSecurityGroup.java From attic-stratos with Apache License 2.0 | 4 votes |
@Inject public AWSEC2SecurityGroupToSecurityGroup(@Memoized Supplier<Set<? extends Location>> locations) { super(locations); }
Example #27
Source File: AliOSSBlobStore.java From multiapps-controller with Apache License 2.0 | 4 votes |
@Override public boolean createContainerInLocation(Location location, String container) { throw new UnsupportedOperationException(); }
Example #28
Source File: AliOSSBlobStore.java From multiapps-controller with Apache License 2.0 | 4 votes |
@Override public boolean createContainerInLocation(Location location, String container, CreateContainerOptions options) { throw new UnsupportedOperationException(); }
Example #29
Source File: BlobUploader.java From jclouds-examples with Apache License 2.0 | 4 votes |
@Override public void run() { /** * Instantiate the ThreadLocal variables when this thread runs for the first time. * Instantiating this in the constructor will not work (different thread). */ if (blobStore.get() == null) { // It is usually a good idea to include the currentThread when logging parallel tasks. System.out.println("Creating connection for thread " + Thread.currentThread()); /** * In some cases, especially when running very large jobs with many parallel threads, some connections will * break. In that case, we need to be able to obtain a new connection (and socket) to the service, which is * why this is factored out. */ resetBlobstore(username, password, provider, region); } if (container.get() == null) { container.set(UUID.randomUUID().toString()); Location location = getOnlyElement(blobStore.get().listAssignableLocations()); blobStore.get().createContainerInLocation(location, container.get()); System.out.println("Created container " + container.get() + " for thread " + Thread.currentThread() + " in " + location.toString()); } // The md5 as returned by the service, and as calculated locally. String md5Local; String md5Remote; Blob blob; try { md5Local = BaseEncoding.base16().encode(Files.hash(file, Hashing.md5()).asBytes()).toLowerCase(); } catch (java.io.IOException e) { e.printStackTrace(); /** * The file is no longer available on the local FS. * In some application cases, you might also want to retry this instead of finishing the unit of work. */ return; } ByteSourcePayload bsp = new ByteSourcePayload(Files.asByteSource(file)); /** * Uploading a file over a network is an inherently fragile operation. Over thousands of files, especially in * highly parallel jobs that tax upload bandwidth, a small percent of uploads are guaranteed to fail. */ do { System.out.println("Uploading " + file.getName() + " ; " + FileUtils.sizeOf(file)); blob = blobStore.get().blobBuilder(file.getName()) .payload(bsp) .build(); md5Remote = blobStore.get().putBlob(container.get(), blob).toLowerCase(); if (md5Local.equals(md5Remote)) { long total = BlobUploaderMain.bytesUploaded.addAndGet(FileUtils.sizeOf(file)); System.out.println("Uploaded MB: " + (int)total / FileUtils.ONE_MB + "MB ; " + (int)((float)BlobUploaderMain.bytesUploaded.get() / BlobUploaderMain.totalBytes) * 100 + "%"); bsp.release(); return; } else { System.out.printf("md5 mismatch %s vs %s, retrying %s", md5Local, md5Remote, file.getName()); } } while(true); }
Example #30
Source File: AreWeConsistentYet.java From are-we-consistent-yet with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { Options options = new Options(); CmdLineParser parser = new CmdLineParser(options); try { parser.parseArgument(args); } catch (CmdLineException cle) { PrintStream err = System.err; err.println("are-we-consistent-yet version " + AreWeConsistentYet.class.getPackage() .getImplementationVersion()); err.println("Usage: are-we-consistent-yet" + " --container-name NAME --properties FILE [options...]"); parser.printUsage(err); System.exit(1); } Properties properties = new Properties(); try (InputStream is = new FileInputStream(options.propertiesFile)) { properties.load(is); } Properties propertiesRead = (Properties) properties.clone(); if (options.readerEndpoint != null) { propertiesRead.setProperty(Constants.PROPERTY_ENDPOINT, options.readerEndpoint); } try (BlobStoreContext context = blobStoreContextFromProperties( properties); BlobStoreContext contextRead = blobStoreContextFromProperties( propertiesRead)) { BlobStore blobStore = context.getBlobStore(); BlobStore blobStoreRead = contextRead.getBlobStore(); Location location = null; if (options.location != null) { for (Location loc : blobStore.listAssignableLocations()) { if (loc.getId().equalsIgnoreCase(options.location)) { location = loc; break; } } if (location == null) { throw new Exception("Could not find location: " + options.location); } } blobStore.createContainerInLocation(location, options.containerName); AreWeConsistentYet test = new AreWeConsistentYet( blobStore, blobStoreRead, options.containerName, options.iterations, options.objectSize); PrintStream out = System.out; out.println("eventual consistency count with " + options.iterations + " iterations: "); out.println("read after create: " + test.readAfterCreate()); out.println("read after delete: " + test.readAfterDelete()); out.println("read after overwrite: " + test.readAfterOverwrite()); out.println("list after create: " + test.listAfterCreate()); out.println("list after delete: " + test.listAfterDelete()); blobStore.deleteContainer(options.containerName); } }