summaryrefslogtreecommitdiffstats
path: root/node-admin
diff options
context:
space:
mode:
authorHåkon Hallingstad <hakon@verizonmedia.com>2019-11-15 14:59:34 +0100
committerHåkon Hallingstad <hakon@verizonmedia.com>2019-11-15 14:59:34 +0100
commitee877c9c2869b15c87a6970a5c809388f49e00a1 (patch)
tree153fbbcbfde60f3de5ed091fad8a1adc1d530043 /node-admin
parentc129fc217618354f902482512138e1c85f213e4d (diff)
Specify millis and put optional params last
Diffstat (limited to 'node-admin')
-rw-r--r--node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/ConfigServerApi.java2
-rw-r--r--node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/ConfigServerApiImpl.java9
-rw-r--r--node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/orchestrator/OrchestratorImpl.java8
-rw-r--r--node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/configserver/orchestrator/OrchestratorImplTest.java44
4 files changed, 23 insertions, 40 deletions
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/ConfigServerApi.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/ConfigServerApi.java
index b006de26566..e6d719e66bb 100644
--- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/ConfigServerApi.java
+++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/ConfigServerApi.java
@@ -28,7 +28,7 @@ public interface ConfigServerApi extends AutoCloseable {
<T> T put(String path, Optional<Object> bodyJsonPojo, Class<T> wantedReturnType);
- <T> T put(Params params, String path, Optional<Object> bodyJsonPojo, Class<T> wantedReturnType);
+ <T> T put(String path, Optional<Object> bodyJsonPojo, Class<T> wantedReturnType, Params params);
<T> T patch(String path, Object bodyJsonPojo, Class<T> wantedReturnType);
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/ConfigServerApiImpl.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/ConfigServerApiImpl.java
index da521a20777..4663562f8e5 100644
--- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/ConfigServerApiImpl.java
+++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/ConfigServerApiImpl.java
@@ -32,7 +32,6 @@ import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
-import java.time.Duration;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -135,11 +134,11 @@ public class ConfigServerApiImpl implements ConfigServerApi {
@Override
public <T> T put(String path, Optional<Object> bodyJsonPojo, Class<T> wantedReturnType) {
- return put(null, path, bodyJsonPojo, wantedReturnType);
+ return put(path, bodyJsonPojo, wantedReturnType, null);
}
@Override
- public <T> T put(Params paramsOrNull, String path, Optional<Object> bodyJsonPojo, Class<T> wantedReturnType) {
+ public <T> T put(String path, Optional<Object> bodyJsonPojo, Class<T> wantedReturnType, Params paramsOrNull) {
return tryAllConfigServers(configServer -> {
HttpPut put = new HttpPut(configServer.resolve(path));
setRequestConfigOverride(paramsOrNull, put);
@@ -230,8 +229,8 @@ public class ConfigServerApiImpl implements ConfigServerApi {
RequestConfig.Builder builder = RequestConfig.copy(request.getConfig());
paramsOrNull.getConnectionTimeout().ifPresent(connectionTimeout -> {
- builder.setConnectTimeout((int) connectionTimeout.getSeconds());
- builder.setSocketTimeout((int) connectionTimeout.getSeconds());
+ builder.setConnectTimeout((int) connectionTimeout.toMillis());
+ builder.setSocketTimeout((int) connectionTimeout.toMillis());
});
request.setConfig(builder.build());
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/orchestrator/OrchestratorImpl.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/orchestrator/OrchestratorImpl.java
index e4dda53343a..20c0604b5dc 100644
--- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/orchestrator/OrchestratorImpl.java
+++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/orchestrator/OrchestratorImpl.java
@@ -47,11 +47,7 @@ public class OrchestratorImpl implements Orchestrator {
UpdateHostResponse response;
try {
var params = new ConfigServerApi.Params().setConnectionTimeout(CONNECTION_TIMEOUT);
- response = configServerApi.put(
- params,
- getSuspendPath(hostName),
- Optional.empty(), /* body */
- UpdateHostResponse.class);
+ response = configServerApi.put(getSuspendPath(hostName), Optional.empty(), UpdateHostResponse.class, params);
} catch (HttpException.NotFoundException n) {
throw new OrchestratorNotFoundException("Failed to suspend " + hostName + ", host not found");
} catch (HttpException e) {
@@ -75,7 +71,7 @@ public class OrchestratorImpl implements Orchestrator {
String hostnames = String.join("&hostname=", hostNames);
String url = String.format("%s/%s?hostname=%s", ORCHESTRATOR_PATH_PREFIX_HOST_SUSPENSION_API,
parentHostName, hostnames);
- batchOperationResult = configServerApi.put(params, url, Optional.empty(), BatchOperationResult.class);
+ batchOperationResult = configServerApi.put(url, Optional.empty(), BatchOperationResult.class, params);
} catch (HttpException e) {
throw new OrchestratorException("Failed to batch suspend for " + parentHostName + ": " + e.toString());
} catch (ConnectionException e) {
diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/configserver/orchestrator/OrchestratorImplTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/configserver/orchestrator/OrchestratorImplTest.java
index 052fdb50a6a..936a7bb224d 100644
--- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/configserver/orchestrator/OrchestratorImplTest.java
+++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/configserver/orchestrator/OrchestratorImplTest.java
@@ -30,10 +30,10 @@ public class OrchestratorImplTest {
@Test
public void testSuspendCall() {
when(configServerApi.put(
- any(),
eq(OrchestratorImpl.ORCHESTRATOR_PATH_PREFIX_HOST_API + "/" + hostName+ "/suspended"),
eq(Optional.empty()),
- eq(UpdateHostResponse.class)
+ eq(UpdateHostResponse.class),
+ any()
)).thenReturn(new UpdateHostResponse(hostName, null));
orchestrator.suspend(hostName);
@@ -42,10 +42,10 @@ public class OrchestratorImplTest {
@Test(expected=OrchestratorException.class)
public void testSuspendCallWithFailureReason() {
when(configServerApi.put(
- any(),
eq(OrchestratorImpl.ORCHESTRATOR_PATH_PREFIX_HOST_API + "/" + hostName+ "/suspended"),
eq(Optional.empty()),
- eq(UpdateHostResponse.class)
+ eq(UpdateHostResponse.class),
+ any()
)).thenReturn(new UpdateHostResponse(hostName, new HostStateChangeDenialReason("hostname", "fail")));
orchestrator.suspend(hostName);
@@ -53,24 +53,16 @@ public class OrchestratorImplTest {
@Test(expected=OrchestratorNotFoundException.class)
public void testSuspendCallWithNotFound() {
- when(configServerApi.put(
- any(),
- any(String.class),
- any(),
- any()
- )).thenThrow(new HttpException.NotFoundException("Not Found"));
+ when(configServerApi.put(any(String.class), any(), any(), any()))
+ .thenThrow(new HttpException.NotFoundException("Not Found"));
orchestrator.suspend(hostName);
}
@Test(expected=RuntimeException.class)
public void testSuspendCallWithSomeOtherException() {
- when(configServerApi.put(
- any(),
- any(String.class),
- any(),
- any()
- )).thenThrow(new RuntimeException("Some parameter was wrong"));
+ when(configServerApi.put(any(String.class), any(), any(), any()))
+ .thenThrow(new RuntimeException("Some parameter was wrong"));
orchestrator.suspend(hostName);
}
@@ -108,12 +100,8 @@ public class OrchestratorImplTest {
@Test(expected=RuntimeException.class)
public void testResumeCallWithSomeOtherException() {
- when(configServerApi.put(
- any(),
- any(String.class),
- any(),
- any()
- )).thenThrow(new RuntimeException("Some parameter was wrong"));
+ when(configServerApi.put(any(String.class), any(), any(), any()))
+ .thenThrow(new RuntimeException("Some parameter was wrong"));
orchestrator.suspend(hostName);
}
@@ -124,10 +112,10 @@ public class OrchestratorImplTest {
List<String> hostNames = Arrays.asList("a1.host1.test.yahoo.com", "a2.host1.test.yahoo.com");
when(configServerApi.put(
- any(),
eq("/orchestrator/v1/suspensions/hosts/host1.test.yahoo.com?hostname=a1.host1.test.yahoo.com&hostname=a2.host1.test.yahoo.com"),
eq(Optional.empty()),
- eq(BatchOperationResult.class)
+ eq(BatchOperationResult.class),
+ any()
)).thenReturn(BatchOperationResult.successResult());
orchestrator.suspend(parentHostName, hostNames);
@@ -140,10 +128,10 @@ public class OrchestratorImplTest {
String failureReason = "Failed to suspend";
when(configServerApi.put(
- any(),
eq("/orchestrator/v1/suspensions/hosts/host1.test.yahoo.com?hostname=a1.host1.test.yahoo.com&hostname=a2.host1.test.yahoo.com"),
eq(Optional.empty()),
- eq(BatchOperationResult.class)
+ eq(BatchOperationResult.class),
+ any()
)).thenReturn(new BatchOperationResult(failureReason));
orchestrator.suspend(parentHostName, hostNames);
@@ -156,10 +144,10 @@ public class OrchestratorImplTest {
String exceptionMessage = "Exception: Something crashed!";
when(configServerApi.put(
- any(),
eq("/orchestrator/v1/suspensions/hosts/host1.test.yahoo.com?hostname=a1.host1.test.yahoo.com&hostname=a2.host1.test.yahoo.com"),
eq(Optional.empty()),
- eq(BatchOperationResult.class)
+ eq(BatchOperationResult.class),
+ any()
)).thenThrow(new RuntimeException(exceptionMessage));
orchestrator.suspend(parentHostName, hostNames);