Skip to content

Commit 10beb68

Browse files
committed
Add keystore.type, deployment.name and deployment.slot settings for discovery
We can now support two new options: * `deployment.name`: deployment name if any. Defaults to the value set with `cloud.azure.cloud.service.name`. * `deployment.slot`: either `staging` or `production` (default). (cherry picked from commit 6d7ee49)
1 parent d2541ab commit 10beb68

File tree

3 files changed

+71
-8
lines changed

3 files changed

+71
-8
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,23 @@ other nodes. This feature was not documented before but was existing under `clou
7272
to elasticsearch (aka transport port name). Defaults to `elasticsearch`. In Azure management console, you could define
7373
an endpoint `elasticsearch` forwarding for example requests on public IP on port 8100 to the virtual machine on port 9300.
7474
This feature was not documented before but was existing under `cloud.azure.port_name`.
75+
* `deployment.name`: deployment name if any. Defaults to the value set with `cloud.azure.management.cloud.service.name`.
76+
* `deployment.slot`: either `staging` or `production` (default).
7577

78+
For example:
79+
80+
```
81+
discovery:
82+
type: azure
83+
azure:
84+
host:
85+
type: private_ip
86+
endpoint:
87+
name: elasticsearch
88+
deployment:
89+
name: your_azure_cloud_service_name
90+
slot: production
91+
```
7692

7793
How to start (long story)
7894
--------------------------

src/main/java/org/elasticsearch/cloud/azure/management/AzureComputeService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ static public final class Fields {
5353

5454
public static final String HOST_TYPE = "host.type";
5555
public static final String ENDPOINT_NAME = "endpoint.name";
56+
public static final String DEPLOYMENT_NAME = "deployment.name";
57+
public static final String DEPLOYMENT_SLOT = "deployment.slot";
5658
}
5759

5860
public HostedServiceGetDetailedResponse getServiceDetails();

src/main/java/org/elasticsearch/discovery/azure/AzureUnicastHostsProvider.java

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,46 @@
4646
public class AzureUnicastHostsProvider extends AbstractComponent implements UnicastHostsProvider {
4747

4848
public static enum HostType {
49-
PRIVATE_IP,
50-
PUBLIC_IP
49+
PRIVATE_IP("private_ip"),
50+
PUBLIC_IP("public_ip");
51+
52+
private String type ;
53+
54+
private HostType(String type) {
55+
this.type = type ;
56+
}
57+
58+
public static HostType fromString(String type) {
59+
for (HostType hostType : values()) {
60+
if (hostType.type.equalsIgnoreCase(type)) {
61+
return hostType;
62+
}
63+
}
64+
return null;
65+
}
5166
}
5267

68+
public static enum Deployment {
69+
PRODUCTION("production", DeploymentSlot.Production),
70+
STAGING("staging", DeploymentSlot.Staging);
71+
72+
private String deployment;
73+
private DeploymentSlot slot;
74+
75+
private Deployment(String deployment, DeploymentSlot slot) {
76+
this.deployment = deployment;
77+
this.slot = slot;
78+
}
79+
80+
public static Deployment fromString(String string) {
81+
for (Deployment deployment : values()) {
82+
if (deployment.deployment.equalsIgnoreCase(string)) {
83+
return deployment;
84+
}
85+
}
86+
return null;
87+
}
88+
}
5389

5490
private final AzureComputeService azureComputeService;
5591
private TransportService transportService;
@@ -78,12 +114,10 @@ public AzureUnicastHostsProvider(Settings settings, AzureComputeService azureCom
78114
this.refreshInterval = componentSettings.getAsTime(Fields.REFRESH,
79115
settings.getAsTime("cloud.azure." + Fields.REFRESH, TimeValue.timeValueSeconds(0)));
80116

81-
HostType tmpHostType;
82117
String strHostType = componentSettings.get(Fields.HOST_TYPE,
83118
settings.get("cloud.azure." + Fields.HOST_TYPE_DEPRECATED, HostType.PRIVATE_IP.name())).toUpperCase();
84-
try {
85-
tmpHostType = HostType.valueOf(strHostType);
86-
} catch (IllegalArgumentException e) {
119+
HostType tmpHostType = HostType.fromString(strHostType);
120+
if (tmpHostType == null) {
87121
logger.warn("wrong value for [{}]: [{}]. falling back to [{}]...", Fields.HOST_TYPE,
88122
strHostType, HostType.PRIVATE_IP.name().toLowerCase());
89123
tmpHostType = HostType.PRIVATE_IP;
@@ -99,8 +133,19 @@ public AzureUnicastHostsProvider(Settings settings, AzureComputeService azureCom
99133
this.publicEndpointName = componentSettings.get(Fields.ENDPOINT_NAME, "elasticsearch");
100134
}
101135

102-
this.deploymentName = componentSettings.get(Fields.SERVICE_NAME, settings.get("cloud.azure." + Fields.SERVICE_NAME_DEPRECATED));
103-
this.deploymentSlot = DeploymentSlot.Production;
136+
this.deploymentName = componentSettings.get(Fields.DEPLOYMENT_NAME,
137+
settings.get("cloud.azure.management." + Fields.SERVICE_NAME,
138+
settings.get("cloud.azure." + Fields.SERVICE_NAME_DEPRECATED)));
139+
140+
// Reading deployment_slot
141+
String strDeployment = componentSettings.get(Fields.DEPLOYMENT_SLOT, Deployment.PRODUCTION.deployment);
142+
Deployment tmpDeployment = Deployment.fromString(strDeployment);
143+
if (tmpDeployment == null) {
144+
logger.warn("wrong value for [{}]: [{}]. falling back to [{}]...", Fields.DEPLOYMENT_SLOT,
145+
strDeployment, Deployment.PRODUCTION.deployment);
146+
tmpDeployment = Deployment.PRODUCTION;
147+
}
148+
this.deploymentSlot = tmpDeployment.slot;
104149
}
105150

106151
/**

0 commit comments

Comments
 (0)