|
| 1 | +/* |
| 2 | + * Copyright 2019 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +// DO NOT EDIT! This is a generated sample ("RequestPaged", "sample_list_recommendations") |
| 17 | +// sample-metadata: |
| 18 | +// title: List Recommendations |
| 19 | +// description: List recommendations for a specified project, location, and recommender. |
| 20 | +// usage: gradle run |
| 21 | +// -PmainClass=com.google.cloud.examples.recommender.v1beta1.SampleListRecommendations |
| 22 | + |
| 23 | +package com.google.cloud.examples.recommender.v1beta1; |
| 24 | + |
| 25 | +import com.google.cloud.recommender.v1beta1.ListRecommendationsRequest; |
| 26 | +import com.google.cloud.recommender.v1beta1.Recommendation; |
| 27 | +import com.google.cloud.recommender.v1beta1.RecommenderClient; |
| 28 | + |
| 29 | +public class SampleListRecommendations { |
| 30 | + // [START ] |
| 31 | + /* |
| 32 | + * Please include the following imports to run this sample. |
| 33 | + * |
| 34 | + * import com.google.cloud.recommender.v1beta1.ListRecommendationsRequest; |
| 35 | + * import com.google.cloud.recommender.v1beta1.Recommendation; |
| 36 | + * import com.google.cloud.recommender.v1beta1.RecommenderClient; |
| 37 | + */ |
| 38 | + |
| 39 | + /** List recommendations for a specified project, location, and recommender. */ |
| 40 | + public static void sampleListRecommendations() { |
| 41 | + try (RecommenderClient recommenderClient = RecommenderClient.create()) { |
| 42 | + String formattedParent = |
| 43 | + RecommenderClient.formatRecommenderName("[PROJECT]", "[LOCATION]", "[RECOMMENDER]"); |
| 44 | + ListRecommendationsRequest request = |
| 45 | + ListRecommendationsRequest.newBuilder().setParent(formattedParent).build(); |
| 46 | + for (Recommendation responseItem : |
| 47 | + recommenderClient.listRecommendations(request).iterateAll()) { |
| 48 | + Recommendation recommendation = responseItem; |
| 49 | + System.out.printf("Recommendation name: %s\n", recommendation.getName()); |
| 50 | + System.out.printf("- description: %s\n", recommendation.getDescription()); |
| 51 | + System.out.printf( |
| 52 | + "- primary_impact.category: %s\n", recommendation.getPrimaryImpact().getCategory()); |
| 53 | + System.out.printf("- state_info.state: %s\n", recommendation.getStateInfo().getState()); |
| 54 | + System.out.printf("- last_refresh_time: %s\n", recommendation.getLastRefreshTime()); |
| 55 | + } |
| 56 | + } catch (Exception exception) { |
| 57 | + System.err.println("Failed to create the client due to: " + exception); |
| 58 | + } |
| 59 | + } |
| 60 | + // [END ] |
| 61 | + |
| 62 | + public static void main(String[] args) { |
| 63 | + sampleListRecommendations(); |
| 64 | + } |
| 65 | +} |
0 commit comments