PageRenderTime 62ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/sdk/costmanagement/azure-resourcemanager-costmanagement/src/main/java/com/azure/resourcemanager/costmanagement/CostManagementManager.java

http://github.com/WindowsAzure/azure-sdk-for-java
Java | 323 lines | 213 code | 37 blank | 73 comment | 24 complexity | 02081cb37c0f80216dd742a32faa37d5 MD5 | raw file
Possible License(s): MIT
  1. // Copyright (c) Microsoft Corporation. All rights reserved.
  2. // Licensed under the MIT License.
  3. // Code generated by Microsoft (R) AutoRest Code Generator.
  4. package com.azure.resourcemanager.costmanagement;
  5. import com.azure.core.credential.TokenCredential;
  6. import com.azure.core.http.HttpClient;
  7. import com.azure.core.http.HttpPipeline;
  8. import com.azure.core.http.HttpPipelineBuilder;
  9. import com.azure.core.http.policy.AddDatePolicy;
  10. import com.azure.core.http.policy.HttpLogOptions;
  11. import com.azure.core.http.policy.HttpLoggingPolicy;
  12. import com.azure.core.http.policy.HttpPipelinePolicy;
  13. import com.azure.core.http.policy.HttpPolicyProviders;
  14. import com.azure.core.http.policy.RequestIdPolicy;
  15. import com.azure.core.http.policy.RetryPolicy;
  16. import com.azure.core.http.policy.UserAgentPolicy;
  17. import com.azure.core.management.http.policy.ArmChallengeAuthenticationPolicy;
  18. import com.azure.core.management.profile.AzureProfile;
  19. import com.azure.core.util.Configuration;
  20. import com.azure.core.util.logging.ClientLogger;
  21. import com.azure.resourcemanager.costmanagement.fluent.CostManagementClient;
  22. import com.azure.resourcemanager.costmanagement.implementation.AlertsImpl;
  23. import com.azure.resourcemanager.costmanagement.implementation.CostManagementClientBuilder;
  24. import com.azure.resourcemanager.costmanagement.implementation.DimensionsImpl;
  25. import com.azure.resourcemanager.costmanagement.implementation.ExportsImpl;
  26. import com.azure.resourcemanager.costmanagement.implementation.ForecastsImpl;
  27. import com.azure.resourcemanager.costmanagement.implementation.GenerateReservationDetailsReportsImpl;
  28. import com.azure.resourcemanager.costmanagement.implementation.OperationsImpl;
  29. import com.azure.resourcemanager.costmanagement.implementation.QueriesImpl;
  30. import com.azure.resourcemanager.costmanagement.implementation.SettingsImpl;
  31. import com.azure.resourcemanager.costmanagement.implementation.ViewsImpl;
  32. import com.azure.resourcemanager.costmanagement.models.Alerts;
  33. import com.azure.resourcemanager.costmanagement.models.Dimensions;
  34. import com.azure.resourcemanager.costmanagement.models.Exports;
  35. import com.azure.resourcemanager.costmanagement.models.Forecasts;
  36. import com.azure.resourcemanager.costmanagement.models.GenerateReservationDetailsReports;
  37. import com.azure.resourcemanager.costmanagement.models.Operations;
  38. import com.azure.resourcemanager.costmanagement.models.Queries;
  39. import com.azure.resourcemanager.costmanagement.models.Settings;
  40. import com.azure.resourcemanager.costmanagement.models.Views;
  41. import java.time.Duration;
  42. import java.time.temporal.ChronoUnit;
  43. import java.util.ArrayList;
  44. import java.util.List;
  45. import java.util.Objects;
  46. /** Entry point to CostManagementManager. */
  47. public final class CostManagementManager {
  48. private Settings settings;
  49. private Views views;
  50. private Alerts alerts;
  51. private Forecasts forecasts;
  52. private Dimensions dimensions;
  53. private Queries queries;
  54. private GenerateReservationDetailsReports generateReservationDetailsReports;
  55. private Operations operations;
  56. private Exports exports;
  57. private final CostManagementClient clientObject;
  58. private CostManagementManager(HttpPipeline httpPipeline, AzureProfile profile, Duration defaultPollInterval) {
  59. Objects.requireNonNull(httpPipeline, "'httpPipeline' cannot be null.");
  60. Objects.requireNonNull(profile, "'profile' cannot be null.");
  61. this.clientObject =
  62. new CostManagementClientBuilder()
  63. .pipeline(httpPipeline)
  64. .endpoint(profile.getEnvironment().getResourceManagerEndpoint())
  65. .defaultPollInterval(defaultPollInterval)
  66. .buildClient();
  67. }
  68. /**
  69. * Creates an instance of CostManagement service API entry point.
  70. *
  71. * @param credential the credential to use.
  72. * @param profile the Azure profile for client.
  73. * @return the CostManagement service API instance.
  74. */
  75. public static CostManagementManager authenticate(TokenCredential credential, AzureProfile profile) {
  76. Objects.requireNonNull(credential, "'credential' cannot be null.");
  77. Objects.requireNonNull(profile, "'profile' cannot be null.");
  78. return configure().authenticate(credential, profile);
  79. }
  80. /**
  81. * Gets a Configurable instance that can be used to create CostManagementManager with optional configuration.
  82. *
  83. * @return the Configurable instance allowing configurations.
  84. */
  85. public static Configurable configure() {
  86. return new CostManagementManager.Configurable();
  87. }
  88. /** The Configurable allowing configurations to be set. */
  89. public static final class Configurable {
  90. private final ClientLogger logger = new ClientLogger(Configurable.class);
  91. private HttpClient httpClient;
  92. private HttpLogOptions httpLogOptions;
  93. private final List<HttpPipelinePolicy> policies = new ArrayList<>();
  94. private final List<String> scopes = new ArrayList<>();
  95. private RetryPolicy retryPolicy;
  96. private Duration defaultPollInterval;
  97. private Configurable() {
  98. }
  99. /**
  100. * Sets the http client.
  101. *
  102. * @param httpClient the HTTP client.
  103. * @return the configurable object itself.
  104. */
  105. public Configurable withHttpClient(HttpClient httpClient) {
  106. this.httpClient = Objects.requireNonNull(httpClient, "'httpClient' cannot be null.");
  107. return this;
  108. }
  109. /**
  110. * Sets the logging options to the HTTP pipeline.
  111. *
  112. * @param httpLogOptions the HTTP log options.
  113. * @return the configurable object itself.
  114. */
  115. public Configurable withLogOptions(HttpLogOptions httpLogOptions) {
  116. this.httpLogOptions = Objects.requireNonNull(httpLogOptions, "'httpLogOptions' cannot be null.");
  117. return this;
  118. }
  119. /**
  120. * Adds the pipeline policy to the HTTP pipeline.
  121. *
  122. * @param policy the HTTP pipeline policy.
  123. * @return the configurable object itself.
  124. */
  125. public Configurable withPolicy(HttpPipelinePolicy policy) {
  126. this.policies.add(Objects.requireNonNull(policy, "'policy' cannot be null."));
  127. return this;
  128. }
  129. /**
  130. * Adds the scope to permission sets.
  131. *
  132. * @param scope the scope.
  133. * @return the configurable object itself.
  134. */
  135. public Configurable withScope(String scope) {
  136. this.scopes.add(Objects.requireNonNull(scope, "'scope' cannot be null."));
  137. return this;
  138. }
  139. /**
  140. * Sets the retry policy to the HTTP pipeline.
  141. *
  142. * @param retryPolicy the HTTP pipeline retry policy.
  143. * @return the configurable object itself.
  144. */
  145. public Configurable withRetryPolicy(RetryPolicy retryPolicy) {
  146. this.retryPolicy = Objects.requireNonNull(retryPolicy, "'retryPolicy' cannot be null.");
  147. return this;
  148. }
  149. /**
  150. * Sets the default poll interval, used when service does not provide "Retry-After" header.
  151. *
  152. * @param defaultPollInterval the default poll interval.
  153. * @return the configurable object itself.
  154. */
  155. public Configurable withDefaultPollInterval(Duration defaultPollInterval) {
  156. this.defaultPollInterval = Objects.requireNonNull(defaultPollInterval, "'retryPolicy' cannot be null.");
  157. if (this.defaultPollInterval.isNegative()) {
  158. throw logger.logExceptionAsError(new IllegalArgumentException("'httpPipeline' cannot be negative"));
  159. }
  160. return this;
  161. }
  162. /**
  163. * Creates an instance of CostManagement service API entry point.
  164. *
  165. * @param credential the credential to use.
  166. * @param profile the Azure profile for client.
  167. * @return the CostManagement service API instance.
  168. */
  169. public CostManagementManager authenticate(TokenCredential credential, AzureProfile profile) {
  170. Objects.requireNonNull(credential, "'credential' cannot be null.");
  171. Objects.requireNonNull(profile, "'profile' cannot be null.");
  172. StringBuilder userAgentBuilder = new StringBuilder();
  173. userAgentBuilder
  174. .append("azsdk-java")
  175. .append("-")
  176. .append("com.azure.resourcemanager.costmanagement")
  177. .append("/")
  178. .append("1.0.0-beta.3");
  179. if (!Configuration.getGlobalConfiguration().get("AZURE_TELEMETRY_DISABLED", false)) {
  180. userAgentBuilder
  181. .append(" (")
  182. .append(Configuration.getGlobalConfiguration().get("java.version"))
  183. .append("; ")
  184. .append(Configuration.getGlobalConfiguration().get("os.name"))
  185. .append("; ")
  186. .append(Configuration.getGlobalConfiguration().get("os.version"))
  187. .append("; auto-generated)");
  188. } else {
  189. userAgentBuilder.append(" (auto-generated)");
  190. }
  191. if (scopes.isEmpty()) {
  192. scopes.add(profile.getEnvironment().getManagementEndpoint() + "/.default");
  193. }
  194. if (retryPolicy == null) {
  195. retryPolicy = new RetryPolicy("Retry-After", ChronoUnit.SECONDS);
  196. }
  197. List<HttpPipelinePolicy> policies = new ArrayList<>();
  198. policies.add(new UserAgentPolicy(userAgentBuilder.toString()));
  199. policies.add(new RequestIdPolicy());
  200. HttpPolicyProviders.addBeforeRetryPolicies(policies);
  201. policies.add(retryPolicy);
  202. policies.add(new AddDatePolicy());
  203. policies.add(new ArmChallengeAuthenticationPolicy(credential, scopes.toArray(new String[0])));
  204. policies.addAll(this.policies);
  205. HttpPolicyProviders.addAfterRetryPolicies(policies);
  206. policies.add(new HttpLoggingPolicy(httpLogOptions));
  207. HttpPipeline httpPipeline =
  208. new HttpPipelineBuilder()
  209. .httpClient(httpClient)
  210. .policies(policies.toArray(new HttpPipelinePolicy[0]))
  211. .build();
  212. return new CostManagementManager(httpPipeline, profile, defaultPollInterval);
  213. }
  214. }
  215. /** @return Resource collection API of Settings. */
  216. public Settings settings() {
  217. if (this.settings == null) {
  218. this.settings = new SettingsImpl(clientObject.getSettings(), this);
  219. }
  220. return settings;
  221. }
  222. /** @return Resource collection API of Views. */
  223. public Views views() {
  224. if (this.views == null) {
  225. this.views = new ViewsImpl(clientObject.getViews(), this);
  226. }
  227. return views;
  228. }
  229. /** @return Resource collection API of Alerts. */
  230. public Alerts alerts() {
  231. if (this.alerts == null) {
  232. this.alerts = new AlertsImpl(clientObject.getAlerts(), this);
  233. }
  234. return alerts;
  235. }
  236. /** @return Resource collection API of Forecasts. */
  237. public Forecasts forecasts() {
  238. if (this.forecasts == null) {
  239. this.forecasts = new ForecastsImpl(clientObject.getForecasts(), this);
  240. }
  241. return forecasts;
  242. }
  243. /** @return Resource collection API of Dimensions. */
  244. public Dimensions dimensions() {
  245. if (this.dimensions == null) {
  246. this.dimensions = new DimensionsImpl(clientObject.getDimensions(), this);
  247. }
  248. return dimensions;
  249. }
  250. /** @return Resource collection API of Queries. */
  251. public Queries queries() {
  252. if (this.queries == null) {
  253. this.queries = new QueriesImpl(clientObject.getQueries(), this);
  254. }
  255. return queries;
  256. }
  257. /** @return Resource collection API of GenerateReservationDetailsReports. */
  258. public GenerateReservationDetailsReports generateReservationDetailsReports() {
  259. if (this.generateReservationDetailsReports == null) {
  260. this.generateReservationDetailsReports =
  261. new GenerateReservationDetailsReportsImpl(clientObject.getGenerateReservationDetailsReports(), this);
  262. }
  263. return generateReservationDetailsReports;
  264. }
  265. /** @return Resource collection API of Operations. */
  266. public Operations operations() {
  267. if (this.operations == null) {
  268. this.operations = new OperationsImpl(clientObject.getOperations(), this);
  269. }
  270. return operations;
  271. }
  272. /** @return Resource collection API of Exports. */
  273. public Exports exports() {
  274. if (this.exports == null) {
  275. this.exports = new ExportsImpl(clientObject.getExports(), this);
  276. }
  277. return exports;
  278. }
  279. /**
  280. * @return Wrapped service client CostManagementClient providing direct access to the underlying auto-generated API
  281. * implementation, based on Azure REST API.
  282. */
  283. public CostManagementClient serviceClient() {
  284. return this.clientObject;
  285. }
  286. }