Skip to content

Commit

Permalink
Clean up sample resources after use. (#8828)
Browse files Browse the repository at this point in the history
  • Loading branch information
sima-zhu authored Mar 7, 2020
1 parent 53ce134 commit 8c35d7d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class CreateIndexExample {
*/
private static final String ENDPOINT = Configuration.getGlobalConfiguration().get("AZURE_COGNITIVE_SEARCH_ENDPOINT");
private static final String ADMIN_KEY = Configuration.getGlobalConfiguration().get("AZURE_COGNITIVE_SEARCH_API_KEY");

private static final String INDEX_NAME = "good-food";

public static void main(String[] args) {
SearchApiKeyCredential searchApiKeyCredential = new SearchApiKeyCredential(ADMIN_KEY);
Expand All @@ -28,7 +28,7 @@ public static void main(String[] args) {
.buildClient();

Index newIndex = new Index()
.setName("good-food")
.setName(INDEX_NAME)
.setFields(
Arrays.asList(new Field()
.setName("Name")
Expand All @@ -37,7 +37,10 @@ public static void main(String[] args) {
new Field()
.setName("Cuisine")
.setType(DataType.EDM_STRING)));

// Create index.
client.createIndex(newIndex);

// Cleanup index resource.
client.deleteIndex(INDEX_NAME);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class CreateSkillsetExample {
*/
private static final String ENDPOINT = Configuration.getGlobalConfiguration().get("AZURE_COGNITIVE_SEARCH_ENDPOINT");
private static final String ADMIN_KEY = Configuration.getGlobalConfiguration().get("AZURE_COGNITIVE_SEARCH_ADMIN_KEY");
private static final String OCR_SKILLSET_NAME = "ocr-skillset";
private static final String CUSTOME_SKILLSET_NAME = "custom-skillset";

public static void main(String[] args) {
SearchServiceClient searchServiceClient = new SearchServiceClientBuilder()
Expand All @@ -33,6 +35,7 @@ public static void main(String[] args) {

createOcrSkillset(searchServiceClient);
createCustomSkillset(searchServiceClient);
cleanupSkillset(searchServiceClient);
}

private static void createOcrSkillset(SearchServiceClient searchServiceClient) {
Expand Down Expand Up @@ -66,7 +69,7 @@ private static void createOcrSkillset(SearchServiceClient searchServiceClient) {
);

Skillset skillset = new Skillset()
.setName("ocr-skillset")
.setName(OCR_SKILLSET_NAME)
.setDescription("Extracts text (plain and structured) from image.")
.setSkills(skills);

Expand Down Expand Up @@ -107,7 +110,7 @@ private static void createCustomSkillset(SearchServiceClient searchServiceClient
.setDescription("A WebApiSkill that can be used to call a custom web api function");

Skillset skillset = new Skillset()
.setName("custom-skillset")
.setName(CUSTOME_SKILLSET_NAME)
.setDescription("Skillset for testing custom skillsets")
.setSkills(Collections.singletonList(webApiSkill));

Expand All @@ -119,4 +122,9 @@ private static void createCustomSkillset(SearchServiceClient searchServiceClient
System.out.println(String.format("Name: %s", createdSkillset.getName()));
System.out.println(String.format("ETag: %s", createdSkillset.getETag()));
}

private static void cleanupSkillset(SearchServiceClient searchServiceClient) {
searchServiceClient.deleteSkillset(OCR_SKILLSET_NAME);
searchServiceClient.deleteSkillset(CUSTOME_SKILLSET_NAME);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,14 @@ public class LifecycleSetupExample {
private static final String COSMOS_CONNECTION_STRING = "AccountEndpoint=https://hotels-docbb.documents.azure.com:443/;AccountKey=4UPsNZyFAjgZ1tzHPGZaxS09XcwLrIawbXBWk6IixcxJoSePTcjBn0mi53XiKWu8MaUgowUhIovOv7kjksqAug==;Database=SampleData";
private static final String COSMOS_COLLECTION_NAME = "hotels";

private static final String INDEX_NAME = "hotels-sample-index";
private static final String DATASOURCE_NAME = "hotels-sample-datasource";
private static final String SKILLSET_NAME = "hotels-sample-skillset";
private static final String INDEXER_NAME = "hotels-sample-indexer";
private static final String INDEX_NAME = "hotels-sample-index1";
private static final String DATASOURCE_NAME = "hotels-sample-datasource1";
private static final String SKILLSET_NAME = "hotels-sample-skillset1";
private static final String INDEXER_NAME = "hotels-sample-indexer1";
private static final String SUGGESTER_NAME = "sg";

public static void main(String[] args) {
SearchServiceClient client = createServiceClient();

// Create a data source for a Cosmos DB database
DataSource dataSource = createCosmosDataSource(client);
System.out.println("Created DataSource " + dataSource.getName());
Expand All @@ -72,6 +71,10 @@ public static void main(String[] args) {
// Update indexer schedule
updateIndexerSchedule(client, indexer);
System.out.println("Updated Indexer Schedule " + indexer.getName());

// Clean up resources.
client.deleteIndex(INDEX_NAME);
client.deleteIndexer(INDEXER_NAME);
}

private static SearchServiceClient createServiceClient() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public static void main(String[] args) {
assignSynonymMapToIndex(synonymMapName);

System.out.println("Complete....\n");

// Clean up resources
serviceClient.deleteSynonymMap(synonymMapName);
}

private static void createSynonymMap(SearchServiceClient serviceClient, String synonymMapName) {
Expand Down

0 comments on commit 8c35d7d

Please sign in to comment.