|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | +// Code generated by Microsoft (R) AutoRest Code Generator. |
| 4 | + |
| 5 | +package com.azure.resourcemanager.monitor.generated; |
| 6 | + |
| 7 | +import com.azure.core.credential.TokenCredential; |
| 8 | +import com.azure.core.http.HttpClient; |
| 9 | +import com.azure.core.http.HttpPipeline; |
| 10 | +import com.azure.core.http.HttpPipelineBuilder; |
| 11 | +import com.azure.core.http.policy.AddDatePolicy; |
| 12 | +import com.azure.core.http.policy.BearerTokenAuthenticationPolicy; |
| 13 | +import com.azure.core.http.policy.HttpLogOptions; |
| 14 | +import com.azure.core.http.policy.HttpLoggingPolicy; |
| 15 | +import com.azure.core.http.policy.HttpPipelinePolicy; |
| 16 | +import com.azure.core.http.policy.HttpPolicyProviders; |
| 17 | +import com.azure.core.http.policy.RequestIdPolicy; |
| 18 | +import com.azure.core.http.policy.RetryPolicy; |
| 19 | +import com.azure.core.http.policy.UserAgentPolicy; |
| 20 | +import com.azure.core.management.profile.AzureProfile; |
| 21 | +import com.azure.core.util.Configuration; |
| 22 | +import com.azure.core.util.logging.ClientLogger; |
| 23 | +import com.azure.resourcemanager.monitor.generated.fluent.MonitorClient; |
| 24 | +import com.azure.resourcemanager.monitor.generated.implementation.ActivityLogAlertsImpl; |
| 25 | +import com.azure.resourcemanager.monitor.generated.implementation.MonitorClientBuilder; |
| 26 | +import com.azure.resourcemanager.monitor.generated.models.ActivityLogAlerts; |
| 27 | +import java.time.Duration; |
| 28 | +import java.time.temporal.ChronoUnit; |
| 29 | +import java.util.ArrayList; |
| 30 | +import java.util.List; |
| 31 | +import java.util.Objects; |
| 32 | + |
| 33 | +/** Entry point to MonitorManager. Monitor Management Client. */ |
| 34 | +public final class MonitorManager { |
| 35 | + private ActivityLogAlerts activityLogAlerts; |
| 36 | + |
| 37 | + private final MonitorClient clientObject; |
| 38 | + |
| 39 | + private MonitorManager(HttpPipeline httpPipeline, AzureProfile profile, Duration defaultPollInterval) { |
| 40 | + Objects.requireNonNull(httpPipeline, "'httpPipeline' cannot be null."); |
| 41 | + Objects.requireNonNull(profile, "'profile' cannot be null."); |
| 42 | + this.clientObject = |
| 43 | + new MonitorClientBuilder() |
| 44 | + .pipeline(httpPipeline) |
| 45 | + .endpoint(profile.getEnvironment().getResourceManagerEndpoint()) |
| 46 | + .subscriptionId(profile.getSubscriptionId()) |
| 47 | + .defaultPollInterval(defaultPollInterval) |
| 48 | + .buildClient(); |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * Creates an instance of Monitor service API entry point. |
| 53 | + * |
| 54 | + * @param credential the credential to use. |
| 55 | + * @param profile the Azure profile for client. |
| 56 | + * @return the Monitor service API instance. |
| 57 | + */ |
| 58 | + public static MonitorManager authenticate(TokenCredential credential, AzureProfile profile) { |
| 59 | + Objects.requireNonNull(credential, "'credential' cannot be null."); |
| 60 | + Objects.requireNonNull(profile, "'profile' cannot be null."); |
| 61 | + return configure().authenticate(credential, profile); |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * Gets a Configurable instance that can be used to create MonitorManager with optional configuration. |
| 66 | + * |
| 67 | + * @return the Configurable instance allowing configurations. |
| 68 | + */ |
| 69 | + public static Configurable configure() { |
| 70 | + return new MonitorManager.Configurable(); |
| 71 | + } |
| 72 | + |
| 73 | + /** The Configurable allowing configurations to be set. */ |
| 74 | + public static final class Configurable { |
| 75 | + private final ClientLogger logger = new ClientLogger(Configurable.class); |
| 76 | + |
| 77 | + private HttpClient httpClient; |
| 78 | + private HttpLogOptions httpLogOptions; |
| 79 | + private final List<HttpPipelinePolicy> policies = new ArrayList<>(); |
| 80 | + private RetryPolicy retryPolicy; |
| 81 | + private Duration defaultPollInterval; |
| 82 | + |
| 83 | + private Configurable() { |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * Sets the http client. |
| 88 | + * |
| 89 | + * @param httpClient the HTTP client. |
| 90 | + * @return the configurable object itself. |
| 91 | + */ |
| 92 | + public Configurable withHttpClient(HttpClient httpClient) { |
| 93 | + this.httpClient = Objects.requireNonNull(httpClient, "'httpClient' cannot be null."); |
| 94 | + return this; |
| 95 | + } |
| 96 | + |
| 97 | + /** |
| 98 | + * Sets the logging options to the HTTP pipeline. |
| 99 | + * |
| 100 | + * @param httpLogOptions the HTTP log options. |
| 101 | + * @return the configurable object itself. |
| 102 | + */ |
| 103 | + public Configurable withLogOptions(HttpLogOptions httpLogOptions) { |
| 104 | + this.httpLogOptions = Objects.requireNonNull(httpLogOptions, "'httpLogOptions' cannot be null."); |
| 105 | + return this; |
| 106 | + } |
| 107 | + |
| 108 | + /** |
| 109 | + * Adds the pipeline policy to the HTTP pipeline. |
| 110 | + * |
| 111 | + * @param policy the HTTP pipeline policy. |
| 112 | + * @return the configurable object itself. |
| 113 | + */ |
| 114 | + public Configurable withPolicy(HttpPipelinePolicy policy) { |
| 115 | + this.policies.add(Objects.requireNonNull(policy, "'policy' cannot be null.")); |
| 116 | + return this; |
| 117 | + } |
| 118 | + |
| 119 | + /** |
| 120 | + * Sets the retry policy to the HTTP pipeline. |
| 121 | + * |
| 122 | + * @param retryPolicy the HTTP pipeline retry policy. |
| 123 | + * @return the configurable object itself. |
| 124 | + */ |
| 125 | + public Configurable withRetryPolicy(RetryPolicy retryPolicy) { |
| 126 | + this.retryPolicy = Objects.requireNonNull(retryPolicy, "'retryPolicy' cannot be null."); |
| 127 | + return this; |
| 128 | + } |
| 129 | + |
| 130 | + /** |
| 131 | + * Sets the default poll interval, used when service does not provide "Retry-After" header. |
| 132 | + * |
| 133 | + * @param defaultPollInterval the default poll interval. |
| 134 | + * @return the configurable object itself. |
| 135 | + */ |
| 136 | + public Configurable withDefaultPollInterval(Duration defaultPollInterval) { |
| 137 | + this.defaultPollInterval = Objects.requireNonNull(defaultPollInterval, "'retryPolicy' cannot be null."); |
| 138 | + if (this.defaultPollInterval.isNegative()) { |
| 139 | + throw logger.logExceptionAsError(new IllegalArgumentException("'httpPipeline' cannot be negative")); |
| 140 | + } |
| 141 | + return this; |
| 142 | + } |
| 143 | + |
| 144 | + /** |
| 145 | + * Creates an instance of Monitor service API entry point. |
| 146 | + * |
| 147 | + * @param credential the credential to use. |
| 148 | + * @param profile the Azure profile for client. |
| 149 | + * @return the Monitor service API instance. |
| 150 | + */ |
| 151 | + public MonitorManager authenticate(TokenCredential credential, AzureProfile profile) { |
| 152 | + Objects.requireNonNull(credential, "'credential' cannot be null."); |
| 153 | + Objects.requireNonNull(profile, "'profile' cannot be null."); |
| 154 | + |
| 155 | + StringBuilder userAgentBuilder = new StringBuilder(); |
| 156 | + userAgentBuilder |
| 157 | + .append("azsdk-java") |
| 158 | + .append("-") |
| 159 | + .append("com.azure.resourcemanager.monitor.generated") |
| 160 | + .append("/") |
| 161 | + .append("1.0.0-beta.1"); |
| 162 | + if (!Configuration.getGlobalConfiguration().get("AZURE_TELEMETRY_DISABLED", false)) { |
| 163 | + userAgentBuilder |
| 164 | + .append(" (") |
| 165 | + .append(Configuration.getGlobalConfiguration().get("java.version")) |
| 166 | + .append("; ") |
| 167 | + .append(Configuration.getGlobalConfiguration().get("os.name")) |
| 168 | + .append("; ") |
| 169 | + .append(Configuration.getGlobalConfiguration().get("os.version")) |
| 170 | + .append("; auto-generated)"); |
| 171 | + } else { |
| 172 | + userAgentBuilder.append(" (auto-generated)"); |
| 173 | + } |
| 174 | + |
| 175 | + if (retryPolicy == null) { |
| 176 | + retryPolicy = new RetryPolicy("Retry-After", ChronoUnit.SECONDS); |
| 177 | + } |
| 178 | + List<HttpPipelinePolicy> policies = new ArrayList<>(); |
| 179 | + policies.add(new UserAgentPolicy(userAgentBuilder.toString())); |
| 180 | + policies.add(new RequestIdPolicy()); |
| 181 | + HttpPolicyProviders.addBeforeRetryPolicies(policies); |
| 182 | + policies.add(retryPolicy); |
| 183 | + policies.add(new AddDatePolicy()); |
| 184 | + policies |
| 185 | + .add( |
| 186 | + new BearerTokenAuthenticationPolicy( |
| 187 | + credential, profile.getEnvironment().getManagementEndpoint() + "/.default")); |
| 188 | + HttpPolicyProviders.addAfterRetryPolicies(policies); |
| 189 | + policies.add(new HttpLoggingPolicy(httpLogOptions)); |
| 190 | + HttpPipeline httpPipeline = |
| 191 | + new HttpPipelineBuilder() |
| 192 | + .httpClient(httpClient) |
| 193 | + .policies(policies.toArray(new HttpPipelinePolicy[0])) |
| 194 | + .build(); |
| 195 | + return new MonitorManager(httpPipeline, profile, defaultPollInterval); |
| 196 | + } |
| 197 | + } |
| 198 | + |
| 199 | + /** @return Resource collection API of ActivityLogAlerts. */ |
| 200 | + public ActivityLogAlerts activityLogAlerts() { |
| 201 | + if (this.activityLogAlerts == null) { |
| 202 | + this.activityLogAlerts = new ActivityLogAlertsImpl(clientObject.getActivityLogAlerts(), this); |
| 203 | + } |
| 204 | + return activityLogAlerts; |
| 205 | + } |
| 206 | + |
| 207 | + /** |
| 208 | + * @return Wrapped service client MonitorClient providing direct access to the underlying auto-generated API |
| 209 | + * implementation, based on Azure REST API. |
| 210 | + */ |
| 211 | + public MonitorClient serviceClient() { |
| 212 | + return this.clientObject; |
| 213 | + } |
| 214 | +} |
0 commit comments