46
46
public class AzureUnicastHostsProvider extends AbstractComponent implements UnicastHostsProvider {
47
47
48
48
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
+ }
51
66
}
52
67
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
+ }
53
89
54
90
private final AzureComputeService azureComputeService ;
55
91
private TransportService transportService ;
@@ -78,12 +114,10 @@ public AzureUnicastHostsProvider(Settings settings, AzureComputeService azureCom
78
114
this .refreshInterval = componentSettings .getAsTime (Fields .REFRESH ,
79
115
settings .getAsTime ("cloud.azure." + Fields .REFRESH , TimeValue .timeValueSeconds (0 )));
80
116
81
- HostType tmpHostType ;
82
117
String strHostType = componentSettings .get (Fields .HOST_TYPE ,
83
118
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 ) {
87
121
logger .warn ("wrong value for [{}]: [{}]. falling back to [{}]..." , Fields .HOST_TYPE ,
88
122
strHostType , HostType .PRIVATE_IP .name ().toLowerCase ());
89
123
tmpHostType = HostType .PRIVATE_IP ;
@@ -99,8 +133,19 @@ public AzureUnicastHostsProvider(Settings settings, AzureComputeService azureCom
99
133
this .publicEndpointName = componentSettings .get (Fields .ENDPOINT_NAME , "elasticsearch" );
100
134
}
101
135
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 ;
104
149
}
105
150
106
151
/**
0 commit comments