//snippet-sourcedescription:[CreateDatasetGroup.java demonstrates how to create an Amazon Personalize dataset group.]
//snippet-keyword:[AWS SDK for Java v2]
//snippet-keyword:[Code Sample]
//snippet-service:[Amazon Personalize]
//snippet-sourcetype:[full-example]
//snippet-sourcedate:[5/11/2021]
//snippet-sourceauthor:[seashman - AWS]

/*
   Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
   SPDX-License-Identifier: Apache-2.0
*/

package com.example.personalize;

//snippet-start:[personalize.java2.create_dataset_group.import]
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.personalize.PersonalizeClient;
import software.amazon.awssdk.services.personalize.model.PersonalizeException;
import software.amazon.awssdk.services.personalize.model.CreateDatasetGroupRequest;
import software.amazon.awssdk.services.personalize.model.DescribeDatasetGroupRequest;
import java.time.Instant;
//snippet-end:[personalize.java2.create_dataset_group.import]

public class CreateDatasetGroup {

    public static void main(String [] args) {

        final String USAGE = "Usage:\n" +
                "    CreateDatasetGroup <name>\n\n" +
                "Where:\n" +
                "   name - The name for the new dataset group.\n\n";

        if (args.length != 1) {
            System.out.println(USAGE);
            System.exit(1);
        }

        // Change to the region where your resources are located
        Region region = Region.US_WEST_2;

        String datasetGroupName = args[0];

        PersonalizeClient personalizeClient = PersonalizeClient.builder()
                .region(region)
                .build();

        String datasetGroupArn = createDatasetGroup(personalizeClient, datasetGroupName);
        System.out.println("Dataset group ARN: " + datasetGroupArn);
        personalizeClient.close();
    }
    //snippet-start:[personalize.java2.create_dataset_group.main]
    public static String createDatasetGroup(PersonalizeClient personalizeClient, String datasetGroupName) {

        long waitInMilliseconds = 30 * 1000;

        try {

            CreateDatasetGroupRequest createDatasetGroupRequest = CreateDatasetGroupRequest.builder()
                    .name(datasetGroupName)
                    .build();
            String datasetGroupArn = personalizeClient.createDatasetGroup(createDatasetGroupRequest).datasetGroupArn();

            long maxTime = Instant.now().getEpochSecond() + (15 * 60); // 15 minutes

            DescribeDatasetGroupRequest describeRequest
                    = DescribeDatasetGroupRequest.builder().datasetGroupArn(datasetGroupArn).build();
            String status;

            while (Instant.now().getEpochSecond() < maxTime) {
                status = personalizeClient.describeDatasetGroup(describeRequest).datasetGroup().status();

                System.out.println("DatasetGroup status: " + status);
                if (status.equals("ACTIVE") || status.equals("FAILED")) {
                    break;
                }

                try {
                    Thread.sleep(waitInMilliseconds);
                } catch (InterruptedException e) {
                    System.out.println(e.getMessage());
                }
            }
            return datasetGroupArn;
        }
        catch(PersonalizeException e) {
            System.out.println(e.awsErrorDetails().errorMessage());
        }
        return "";
    }
    //snippet-end:[personalize.java2.create_dataset_group.main]

}

@@ -562,16 +562,18 @@
 mport%5D%0D%0A
+%0D%0A
 import s
@@ -930,24 +930,26 @@
 upRequest;%0D%0A
+%0D%0A
 import java.
@@ -1099,17 +1099,16 @@
 n(String
- 
 %5B%5D args)
@@ -1918,32 +1918,34 @@
 lose();%0D%0A    %7D%0D%0A
+%0D%0A
     //snippet-st
@@ -2110,56 +2110,8 @@
 %0D%0A%0D%0A
-        long waitInMilliseconds = 30 * 1000;%0D%0A%0D%0A
     
@@ -2117,26 +2117,24 @@
      try %7B%0D%0A
-%0D%0A
             
@@ -2316,32 +2316,14 @@
     
-String datasetGroupArn =
+return
  per
@@ -2407,938 +2407,24 @@
 );%0D%0A
-%0D%0A            long maxTime = Instant.now().getEpochSecond() + (15 * 60); // 15 minutes%0D%0A%0D%0A            DescribeDatasetGroupRequest describeRequest%0D%0A                    = DescribeDatasetGroupRequest.builder().datasetGroupArn(datasetGroupArn).build();%0D%0A            String status;%0D%0A%0D%0A            while (Instant.now().getEpochSecond() %3C maxTime) %7B%0D%0A                status = personalizeClient.describeDatasetGroup(describeRequest).datasetGroup().status();%0D%0A%0D%0A                System.out.println(%22DatasetGroup status: %22 + status);%0D%0A                if (status.equals(%22ACTIVE%22) %7C%7C status.equals(%22FAILED%22)) %7B%0D%0A                    break;%0D%0A                %7D%0D%0A%0D%0A                try %7B%0D%0A                    Thread.sleep(waitInMilliseconds);%0D%0A                %7D catch (InterruptedException e) %7B%0D%0A                    System.out.println(e.getMessage());%0D%0A                %7D%0D%0A            %7D%0D%0A            return datasetGroupArn;%0D%0A        %7D%0D%0A        catch
+        %7D catch 
 (Per

Simplify create dataset group code