package com.microsoft.azure.management.trafficmanager.implementation;
import com.microsoft.azure.management.apigeneration.LangDefinition;
import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.ExternalChildResourcesCachedImpl;
import com.microsoft.azure.management.trafficmanager.TrafficManagerAzureEndpoint;
import com.microsoft.azure.management.trafficmanager.TrafficManagerEndpoint;
import com.microsoft.azure.management.trafficmanager.EndpointType;
import com.microsoft.azure.management.trafficmanager.TrafficManagerExternalEndpoint;
import com.microsoft.azure.management.trafficmanager.TrafficManagerNestedProfileEndpoint;
import com.microsoft.azure.management.trafficmanager.TrafficManagerProfile;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@LangDefinition
class TrafficManagerEndpointsImpl extends
ExternalChildResourcesCachedImpl<TrafficManagerEndpointImpl,
TrafficManagerEndpoint,
EndpointInner,
TrafficManagerProfileImpl,
TrafficManagerProfile> {
private final EndpointsInner client;
TrafficManagerEndpointsImpl(EndpointsInner client, TrafficManagerProfileImpl parent) {
super(parent, parent.taskGroup(), "Endpoint");
this.client = client;
this.cacheCollection();
}
List<EndpointInner> allEndpointsInners() {
List<EndpointInner> allEndpoints = new ArrayList<>();
for (TrafficManagerEndpointImpl epImpl : this.collection().values()) {
allEndpoints.add(epImpl.inner());
}
return allEndpoints;
}
Map<String, TrafficManagerAzureEndpoint> azureEndpointsAsMap() {
Map<String, TrafficManagerAzureEndpoint> result = new HashMap<>();
for (Map.Entry<String, TrafficManagerEndpointImpl> entry : this.collection().entrySet()) {
TrafficManagerEndpointImpl endpoint = entry.getValue();
if (endpoint.endpointType() == EndpointType.AZURE) {
TrafficManagerAzureEndpoint azureEndpoint = new TrafficManagerAzureEndpointImpl(entry.getKey(),
this.parent(),
endpoint.inner(),
this.client);
result.put(entry.getKey(), azureEndpoint);
}
}
return Collections.unmodifiableMap(result);
}
Map<String, TrafficManagerExternalEndpoint> externalEndpointsAsMap() {
Map<String, TrafficManagerExternalEndpoint> result = new HashMap<>();
for (Map.Entry<String, TrafficManagerEndpointImpl> entry : this.collection().entrySet()) {
TrafficManagerEndpointImpl endpoint = entry.getValue();
if (endpoint.endpointType() == EndpointType.EXTERNAL) {
TrafficManagerExternalEndpoint externalEndpoint = new TrafficManagerExternalEndpointImpl(entry.getKey(),
this.parent(),
endpoint.inner(),
this.client);
result.put(entry.getKey(), externalEndpoint);
}
}
return Collections.unmodifiableMap(result);
}
Map<String, TrafficManagerNestedProfileEndpoint> nestedProfileEndpointsAsMap() {
Map<String, TrafficManagerNestedProfileEndpoint> result = new HashMap<>();
for (Map.Entry<String, TrafficManagerEndpointImpl> entry : this.collection().entrySet()) {
TrafficManagerEndpointImpl endpoint = entry.getValue();
if (endpoint.endpointType() == EndpointType.NESTED_PROFILE) {
TrafficManagerNestedProfileEndpoint nestedProfileEndpoint = new TrafficManagerNestedProfileEndpointImpl(entry.getKey(),
this.parent(),
endpoint.inner(),
this.client);
result.put(entry.getKey(), nestedProfileEndpoint);
}
}
return Collections.unmodifiableMap(result);
}
public TrafficManagerEndpointImpl defineAzureTargetEndpoint(String name) {
TrafficManagerEndpointImpl endpoint = this.prepareInlineDefine(name);
endpoint.withEndpointType(EndpointType.AZURE);
return endpoint;
}
public TrafficManagerEndpointImpl defineExteralTargetEndpoint(String name) {
TrafficManagerEndpointImpl endpoint = this.prepareInlineDefine(name);
endpoint.withEndpointType(EndpointType.EXTERNAL);
return endpoint;
}
public TrafficManagerEndpointImpl defineNestedProfileTargetEndpoint(String name) {
TrafficManagerEndpointImpl endpoint = this.prepareInlineDefine(name);
endpoint.withEndpointType(EndpointType.NESTED_PROFILE);
return endpoint;
}
public TrafficManagerEndpointImpl updateAzureEndpoint(String name) {
TrafficManagerEndpointImpl endpoint = this.prepareInlineUpdate(name);
if (endpoint.endpointType() != EndpointType.AZURE) {
throw new IllegalArgumentException("An azure endpoint with name " + name + " not found in the profile");
}
return endpoint;
}
public TrafficManagerEndpointImpl updateExternalEndpoint(String name) {
TrafficManagerEndpointImpl endpoint = this.prepareInlineUpdate(name);
if (endpoint.endpointType() != EndpointType.EXTERNAL) {
throw new IllegalArgumentException("An external endpoint with name " + name + " not found in the profile");
}
return endpoint;
}
public TrafficManagerEndpointImpl updateNestedProfileEndpoint(String name) {
TrafficManagerEndpointImpl endpoint = this.prepareInlineUpdate(name);
if (endpoint.endpointType() != EndpointType.NESTED_PROFILE) {
throw new IllegalArgumentException("A nested profile endpoint with name " + name + " not found in the profile");
}
return endpoint;
}
public void remove(String name) {
this.prepareInlineRemove(name);
}
public void addEndpoint(TrafficManagerEndpointImpl endpoint) {
this.addChildResource(endpoint);
}
@Override
protected List<TrafficManagerEndpointImpl> listChildResources() {
List<TrafficManagerEndpointImpl> childResources = new ArrayList<>();
if (parent().inner().endpoints() != null) {
for (EndpointInner inner : parent().inner().endpoints()) {
childResources.add(new TrafficManagerEndpointImpl(inner.name(),
this.parent(),
inner,
this.client));
}
}
return childResources;
}
@Override
protected TrafficManagerEndpointImpl newChildResource(String name) {
TrafficManagerEndpointImpl endpoint = new TrafficManagerEndpointImpl(name,
this.parent(),
new EndpointInner(),
this.client);
return endpoint
.withRoutingWeight(1)
.withTrafficEnabled();
}
}