Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static List<String> synchronousClient(int numberOfInstances) throws Exception {
- long startTime = System.nanoTime();
- System.out.println("-----------------------------------------------------------------------");
- ArrayList<String> instanceIds = new ArrayList<>();
- // Custom client config
- ClientConfiguration clientConfig = ClientConfiguration.builder()
- .connectionTimeoutMillis(3000)
- .readTimeoutMillis(60000)
- .build();
- // Auth provider
- AuthenticationDetailsProvider authenticationDetailsProvider = new ConfigFileAuthenticationDetailsProvider("DEFAULT");
- // Compute client
- ComputeClient computeClient = ComputeClient.builder()
- .configuration(clientConfig)
- .build(authenticationDetailsProvider);
- computeClient.setRegion(Region.valueOf(System.getenv("REGION")));
- // Default values
- String availabilityDomain = System.getenv("AD");
- String compartmentId = System.getenv("COMPARTMENT_ID");
- String imageId = System.getenv("IMAGE_ID");
- String subnetId = System.getenv("SUBNET_ID");
- String shape = System.getenv("SHAPE");
- String instanceName = System.getenv("INSTANCE_NAME_PREFIX");
- for (int i = 0; i < numberOfInstances; i++) {
- long startTime1 = System.nanoTime();
- // Set instance details
- LaunchInstanceDetails launchInstanceDetails = LaunchInstanceDetails.builder()
- .availabilityDomain(availabilityDomain)
- .compartmentId(compartmentId)
- .displayName(instanceName + (i + 1))
- .imageId(imageId)
- .subnetId(subnetId)
- .shape(shape)
- .build();
- // Create request
- LaunchInstanceRequest launchInstanceRequest = LaunchInstanceRequest.builder()
- .launchInstanceDetails(launchInstanceDetails)
- .build();
- // Send request
- LaunchInstanceResponse launchInstanceResponse = computeClient.launchInstance(launchInstanceRequest);
- String instanceId = launchInstanceResponse.getInstance().getId();
- instanceIds.add(instanceId);
- long elapsedTime1 = System.nanoTime() - startTime1;
- System.out.println(instanceId + " created in " + (elapsedTime1 / 1000000) + " ms");
- }
- long elapsedTime = System.nanoTime() - startTime;
- System.out.println("Total execution time in seconds: " + TimeUnit.MILLISECONDS.toSeconds(elapsedTime / 1000000));
- System.out.println("-----------------------------------------------------------------------");
- return instanceIds;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement