@Override public synchronized void setRestartInstanceRequest(String serviceName, long startTimeMs, long endTimeMs, boolean isSuccess, int instanceId) { Preconditions.checkNotNull(serviceName, "Service name should not be null."); Preconditions.checkArgument(instanceId >= 0, "Instance id has to be greater than or equal to zero."); RestartStatus status = isSuccess ? RestartStatus.SUCCESS : RestartStatus.FAILURE; RestartServiceInstancesStatus restartStatus = new RestartServiceInstancesStatus(serviceName, startTimeMs, endTimeMs, status, ImmutableSet.of(instanceId)); String toJson = GSON.toJson(restartStatus, RestartServiceInstancesStatus.class); table.put(Bytes.toBytes(serviceName + "-restart"), Bytes.toBytes(toJson)); }
@Test public void testRestartInstances() throws Exception { String path = String.format("%s/system/services/%s/restart", Constants.Gateway.API_VERSION_3, Constants.Service.APP_FABRIC_HTTP); HttpResponse response = doPost(path); Assert.assertEquals(HttpResponseStatus.OK.code(), response.getResponseCode()); path = String.format("%s/system/services/%s/latest-restart", Constants.Gateway.API_VERSION_3, Constants.Service.APP_FABRIC_HTTP); response = doGet(path); Assert.assertEquals(HttpResponseStatus.OK.code(), response.getResponseCode()); RestartServiceInstancesStatus result = GSON.fromJson(response.getResponseBodyAsString(), RestartServiceInstancesStatus.class); Assert.assertNotNull(result); Assert.assertEquals(Constants.Service.APP_FABRIC_HTTP, result.getServiceName()); Assert.assertEquals(RestartServiceInstancesStatus.RestartStatus.SUCCESS, result.getStatus()); }
@Test public void testInvalidIdRestartInstances() throws Exception { String path = String.format("%s/system/services/%s/instances/1000/restart", Constants.Gateway.API_VERSION_3, Constants.Service.APP_FABRIC_HTTP); HttpResponse response = doPost(path); Assert.assertEquals(HttpResponseStatus.BAD_REQUEST.code(), response.getResponseCode()); path = String.format("%s/system/services/%s/latest-restart", Constants.Gateway.API_VERSION_3, Constants.Service.APP_FABRIC_HTTP); response = doGet(path); Assert.assertEquals(HttpResponseStatus.OK.code(), response.getResponseCode()); RestartServiceInstancesStatus result = GSON.fromJson(response.getResponseBodyAsString(), RestartServiceInstancesStatus.class); Assert.assertNotNull(result); Assert.assertEquals(Constants.Service.APP_FABRIC_HTTP, result.getServiceName()); Assert.assertEquals(RestartServiceInstancesStatus.RestartStatus.FAILURE, result.getStatus()); } }
@Test public void testSingleIdRestartInstances() throws Exception { String path = String.format("%s/system/services/%s/instances/0/restart", Constants.Gateway.API_VERSION_3, Constants.Service.APP_FABRIC_HTTP); HttpResponse response = doPost(path); Assert.assertEquals(HttpResponseStatus.OK.code(), response.getResponseCode()); path = String.format("%s/system/services/%s/latest-restart", Constants.Gateway.API_VERSION_3, Constants.Service.APP_FABRIC_HTTP); response = doGet(path); Assert.assertEquals(HttpResponseStatus.OK.code(), response.getResponseCode()); RestartServiceInstancesStatus result = GSON.fromJson(response.getResponseBodyAsString(), RestartServiceInstancesStatus.class); Assert.assertNotNull(result); Assert.assertEquals(Constants.Service.APP_FABRIC_HTTP, result.getServiceName()); Assert.assertEquals(RestartServiceInstancesStatus.RestartStatus.SUCCESS, result.getStatus()); }
@Override public synchronized void setRestartInstanceRequest(String serviceName, long startTimeMs, long endTimeMs, boolean isSuccess, int instanceId) { Preconditions.checkNotNull(serviceName, "Service name should not be null."); Preconditions.checkArgument(instanceId >= 0, "Instance id has to be greater than or equal to zero."); RestartStatus status = isSuccess ? RestartStatus.SUCCESS : RestartStatus.FAILURE; RestartServiceInstancesStatus restartStatus = new RestartServiceInstancesStatus(serviceName, startTimeMs, endTimeMs, status, ImmutableSet.of(instanceId)); String toJson = GSON.toJson(restartStatus, RestartServiceInstancesStatus.class); table.put(Bytes.toBytes(serviceName + "-restart"), Bytes.toBytes(toJson)); }
@Override public synchronized void setRestartAllInstancesRequest(String serviceName, long startTimeMs, long endTimeMs, boolean isSuccess) { Preconditions.checkNotNull(serviceName, "Service name should not be null."); RestartStatus status = isSuccess ? RestartStatus.SUCCESS : RestartStatus.FAILURE; Integer serviceInstance = getServiceInstance(serviceName); int instanceCount = (serviceInstance == null) ? 0 : serviceInstance; Set<Integer> instancesToRestart = Ranges.closedOpen(0, instanceCount).asSet(DiscreteDomains.integers()); RestartServiceInstancesStatus restartStatus = new RestartServiceInstancesStatus(serviceName, startTimeMs, endTimeMs, status, instancesToRestart); String toJson = GSON.toJson(restartStatus, RestartServiceInstancesStatus.class); table.put(Bytes.toBytes(serviceName + "-restart"), Bytes.toBytes(toJson)); }
@Override public synchronized void setRestartAllInstancesRequest(String serviceName, long startTimeMs, long endTimeMs, boolean isSuccess) { Preconditions.checkNotNull(serviceName, "Service name should not be null."); RestartStatus status = isSuccess ? RestartStatus.SUCCESS : RestartStatus.FAILURE; Integer serviceInstance = getServiceInstance(serviceName); int instanceCount = (serviceInstance == null) ? 0 : serviceInstance; Set<Integer> instancesToRestart = Ranges.closedOpen(0, instanceCount).asSet(DiscreteDomains.integers()); RestartServiceInstancesStatus restartStatus = new RestartServiceInstancesStatus(serviceName, startTimeMs, endTimeMs, status, instancesToRestart); String toJson = GSON.toJson(restartStatus, RestartServiceInstancesStatus.class); table.put(Bytes.toBytes(serviceName + "-restart"), Bytes.toBytes(toJson)); }