3939import javax .crypto .spec .SecretKeySpec ;
4040import java .net .URI ;
4141import java .net .URISyntaxException ;
42+ import java .nio .charset .StandardCharsets ;
4243import java .text .SimpleDateFormat ;
4344import java .util .*;
4445
@@ -50,10 +51,10 @@ public class EcsHostListProvider implements HostListProvider {
5051 public static final int DEFAULT_PORT = 9021 ;
5152
5253 protected final SimpleDateFormat rfc822DateFormat ;
53- private Client client ;
54- private LoadBalancer loadBalancer ;
55- private String user ;
56- private String secret ;
54+ private final Client client ;
55+ private final LoadBalancer loadBalancer ;
56+ private final String user ;
57+ private final String secret ;
5758 private String protocol = DEFAULT_PROTOCOL ;
5859 private int port = DEFAULT_PORT ;
5960 private List <Vdc > vdcs ;
@@ -70,7 +71,7 @@ public EcsHostListProvider(Client client, LoadBalancer loadBalancer, String user
7071 public List <Host > getHostList () {
7172 if (vdcs == null || vdcs .isEmpty ()) return getDataNodes (loadBalancer .getTopHost (null ));
7273
73- List <Host > hostList = new ArrayList <Host >();
74+ List <Host > hostList = new ArrayList <>();
7475
7576 for (Vdc vdc : vdcs ) {
7677 if (vdc .getHosts ().isEmpty ()) log .warn ("VDC " + vdc .getName () + " has no hosts!" );
@@ -111,8 +112,7 @@ public void runHealthCheck(Host host) {
111112 PingItem pingItem = response .getPingItemMap ().get (PingItem .MAINTENANCE_MODE );
112113 if (pingItem != null ) status = pingItem .getStatus ();
113114 }
114- if (status == PingItem .Status .ON ) ((VdcHost ) host ).setMaintenanceMode (true );
115- else ((VdcHost ) host ).setMaintenanceMode (false );
115+ ((VdcHost ) host ).setMaintenanceMode (status == PingItem .Status .ON );
116116 }
117117 }
118118
@@ -153,7 +153,7 @@ protected List<Host> getDataNodes(Host host) {
153153 log .debug ("retrieving VDC node list from {}" , host .getName ());
154154 List <String > dataNodes = request .get (ListDataNode .class ).getDataNodes ();
155155
156- List <Host > hosts = new ArrayList <Host >();
156+ List <Host > hosts = new ArrayList <>();
157157 for (String node : dataNodes ) {
158158 hosts .add (new Host (node ));
159159 }
@@ -171,8 +171,8 @@ protected URI getRequestUri(Host host, String path) {
171171
172172 protected String getSignature (String canonicalString , String secret ) throws Exception {
173173 Mac mac = Mac .getInstance ("HmacSHA1" );
174- mac .init (new SecretKeySpec (secret .getBytes ("UTF-8" ), "HmacSHA1" ));
175- String signature = new String (Base64 .encodeBase64 (mac .doFinal (canonicalString .getBytes ("UTF-8" ))));
174+ mac .init (new SecretKeySpec (secret .getBytes (StandardCharsets . UTF_8 ), "HmacSHA1" ));
175+ String signature = new String (Base64 .encodeBase64 (mac .doFinal (canonicalString .getBytes (StandardCharsets . UTF_8 ))));
176176 log .debug ("canonicalString:\n " + canonicalString );
177177 log .debug ("signature:\n " + signature );
178178 return signature ;
@@ -182,7 +182,7 @@ protected void updateVdcNodes(Vdc vdc, List<Host> nodeList) {
182182 if (nodeList == null || nodeList .isEmpty ()) throw new RuntimeException ("node list is empty" );
183183
184184 // make sure the hosts are associated with the VDC first
185- List <VdcHost > vdcNodeList = new ArrayList <VdcHost >();
185+ List <VdcHost > vdcNodeList = new ArrayList <>();
186186 for (Host host : nodeList ) {
187187 vdcNodeList .add (new VdcHost (vdc , host .getName ()));
188188 }
0 commit comments