@Override @Synchronized public CompletableFuture<DeleteScopeStatus> deleteScope(final String scopeName) { if (scopes.containsKey(scopeName)) { return scopes.get(scopeName).listStreamsInScope().thenApply(streams -> { if (streams.isEmpty()) { scopes.get(scopeName).deleteScope(); scopes.remove(scopeName); return DeleteScopeStatus.newBuilder().setStatus(DeleteScopeStatus.Status.SUCCESS).build(); } else { return DeleteScopeStatus.newBuilder().setStatus(DeleteScopeStatus.Status.SCOPE_NOT_EMPTY).build(); } }); } else { return CompletableFuture.completedFuture(DeleteScopeStatus.newBuilder().setStatus( DeleteScopeStatus.Status.SCOPE_NOT_FOUND).build()); } }
if (scopeStatus.getStatus() == DeleteScopeStatus.Status.SUCCESS) { log.info("Successfully deleted scope: {}", scopeName); return Response.status(Status.NO_CONTENT).build(); } else if (scopeStatus.getStatus() == DeleteScopeStatus.Status.SCOPE_NOT_FOUND) { log.warn("Scope: {} not found", scopeName); return Response.status(Status.NOT_FOUND).build(); } else if (scopeStatus.getStatus() == DeleteScopeStatus.Status.SCOPE_NOT_EMPTY) { log.warn("Cannot delete scope: {} with non-empty streams", scopeName); return Response.status(Status.PRECONDITION_FAILED).build();
public static final com.google.protobuf.Descriptors.EnumDescriptor getDescriptor() { return io.pravega.controller.stream.api.grpc.v1.Controller.DeleteScopeStatus.getDescriptor().getEnumTypes().get(0); }
this.controllerService.deleteScope(ModelHelper.createScopeInfo(SCOPE3), result2); deleteScopeStatus = result2.get(); assertEquals("Delete Empty scope", DeleteScopeStatus.Status.SUCCESS, deleteScopeStatus.getStatus()); deleteScopeStatus = result7.get(); assertEquals("Verify that Scope3 is infact deleted", DeleteScopeStatus.Status.SCOPE_NOT_FOUND, deleteScopeStatus.getStatus()); this.controllerService.deleteScope(ModelHelper.createScopeInfo(SCOPE2), result5); deleteScopeStatus = result5.get(); assertEquals("Delete non empty scope", DeleteScopeStatus.Status.SCOPE_NOT_EMPTY, deleteScopeStatus.getStatus()); deleteScopeStatus = result6.get(); assertEquals("Delete non existent scope", DeleteScopeStatus.Status.SCOPE_NOT_FOUND, deleteScopeStatus.getStatus());
DeleteScopeStatus.newBuilder().setStatus(DeleteScopeStatus.Status.SUCCESS).build())); Response response = addAuthHeaders(client.target(resourceURI).request()).buildDelete().invoke(); assertEquals("Delete Scope response code", 204, response.getStatus()); DeleteScopeStatus.newBuilder().setStatus(DeleteScopeStatus.Status.SCOPE_NOT_EMPTY).build())); response = addAuthHeaders(client.target(resourceURI).request()).buildDelete().invoke(); assertEquals("Delete Scope response code", 412, response.getStatus()); DeleteScopeStatus.newBuilder().setStatus(DeleteScopeStatus.Status.SCOPE_NOT_FOUND).build())); response = addAuthHeaders(client.target(resourceURI).request()).buildDelete().invoke(); assertEquals("Delete Scope response code", 404, response.getStatus()); DeleteScopeStatus.newBuilder().setStatus(DeleteScopeStatus.Status.FAILURE).build())); response = addAuthHeaders(client.target(resourceURI).request()).buildDelete().invoke(); assertEquals("Delete Scope response code", 500, response.getStatus());
@Test public void testDeleteScope() throws ExecutionException, InterruptedException { when(this.mockControllerService.deleteScope(any())).thenReturn( CompletableFuture.completedFuture(Controller.DeleteScopeStatus.newBuilder() .setStatus(Controller.DeleteScopeStatus.Status.SUCCESS).build())); Assert.assertTrue(this.testController.deleteScope("scope").join()); when(this.mockControllerService.deleteScope(any())).thenReturn( CompletableFuture.completedFuture(Controller.DeleteScopeStatus.newBuilder() .setStatus(Controller.DeleteScopeStatus.Status.SCOPE_NOT_FOUND).build())); Assert.assertFalse(this.testController.deleteScope("scope").join()); when(this.mockControllerService.deleteScope(any())).thenReturn( CompletableFuture.completedFuture(Controller.DeleteScopeStatus.newBuilder() .setStatus(Controller.DeleteScopeStatus.Status.FAILURE).build())); assertThrows("Expected ControllerFailureException", () -> this.testController.deleteScope("scope").join(), ex -> ex instanceof ControllerFailureException); when(this.mockControllerService.deleteScope(any())).thenReturn( CompletableFuture.completedFuture(Controller.DeleteScopeStatus.newBuilder() .setStatus(Controller.DeleteScopeStatus.Status.SCOPE_NOT_EMPTY).build())); assertThrows("Expected IllegalStateException", () -> this.testController.deleteScope("scope").join(), ex -> ex instanceof IllegalStateException); when(this.mockControllerService.deleteScope(any())).thenReturn( CompletableFuture.completedFuture(Controller.DeleteScopeStatus.newBuilder() .setStatusValue(-1).build())); assertThrows("Expected ControllerFailureException", () -> this.testController.deleteScope("scope").join(), ex -> ex instanceof ControllerFailureException); }
@io.grpc.stub.annotations.RpcMethod( fullMethodName = SERVICE_NAME + '/' + "deleteScope", requestType = io.pravega.controller.stream.api.grpc.v1.Controller.ScopeInfo.class, responseType = io.pravega.controller.stream.api.grpc.v1.Controller.DeleteScopeStatus.class, methodType = io.grpc.MethodDescriptor.MethodType.UNARY) public static io.grpc.MethodDescriptor<io.pravega.controller.stream.api.grpc.v1.Controller.ScopeInfo, io.pravega.controller.stream.api.grpc.v1.Controller.DeleteScopeStatus> getDeleteScopeMethod() { io.grpc.MethodDescriptor<io.pravega.controller.stream.api.grpc.v1.Controller.ScopeInfo, io.pravega.controller.stream.api.grpc.v1.Controller.DeleteScopeStatus> getDeleteScopeMethod; if ((getDeleteScopeMethod = ControllerServiceGrpc.getDeleteScopeMethod) == null) { synchronized (ControllerServiceGrpc.class) { if ((getDeleteScopeMethod = ControllerServiceGrpc.getDeleteScopeMethod) == null) { ControllerServiceGrpc.getDeleteScopeMethod = getDeleteScopeMethod = io.grpc.MethodDescriptor.<io.pravega.controller.stream.api.grpc.v1.Controller.ScopeInfo, io.pravega.controller.stream.api.grpc.v1.Controller.DeleteScopeStatus>newBuilder() .setType(io.grpc.MethodDescriptor.MethodType.UNARY) .setFullMethodName(generateFullMethodName( "io.pravega.controller.stream.api.grpc.v1.ControllerService", "deleteScope")) .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.pravega.controller.stream.api.grpc.v1.Controller.ScopeInfo.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.pravega.controller.stream.api.grpc.v1.Controller.DeleteScopeStatus.getDefaultInstance())) .setSchemaDescriptor(new ControllerServiceMethodDescriptorSupplier("deleteScope")) .build(); } } } return getDeleteScopeMethod; }
@Override public void deleteScope(ScopeInfo request, StreamObserver<DeleteScopeStatus> responseObserver) { if (request.getScope().equals("scope1")) { responseObserver.onNext(DeleteScopeStatus.newBuilder().setStatus( DeleteScopeStatus.Status.SUCCESS).build()); responseObserver.onCompleted(); } else if (request.getScope().equals("scope2")) { responseObserver.onNext(DeleteScopeStatus.newBuilder().setStatus( DeleteScopeStatus.Status.FAILURE).build()); responseObserver.onCompleted(); } else if (request.getScope().equals("scope3")) { responseObserver.onNext(DeleteScopeStatus.newBuilder() .setStatus(DeleteScopeStatus.Status.SCOPE_NOT_EMPTY) .build()); responseObserver.onCompleted(); } else if (request.getScope().equals("scope4")) { responseObserver.onNext(DeleteScopeStatus.newBuilder() .setStatus(DeleteScopeStatus.Status.SCOPE_NOT_FOUND) .build()); responseObserver.onCompleted(); } else { responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException()); } } };
/** * Delete a scope with given name. * * @param scopeName Name of scope to be deleted * @return DeleteScopeStatus future. */ @Override public CompletableFuture<DeleteScopeStatus> deleteScope(final String scopeName) { return getScope(scopeName).deleteScope().handle((result, ex) -> { if (ex == null) { return DeleteScopeStatus.newBuilder().setStatus(DeleteScopeStatus.Status.SUCCESS).build(); } if (ex.getCause() instanceof StoreException.DataNotFoundException || ex instanceof StoreException.DataNotFoundException) { return DeleteScopeStatus.newBuilder().setStatus(DeleteScopeStatus.Status.SCOPE_NOT_FOUND).build(); } else if (ex.getCause() instanceof StoreException.DataNotEmptyException || ex instanceof StoreException.DataNotEmptyException) { return DeleteScopeStatus.newBuilder().setStatus(DeleteScopeStatus.Status.SCOPE_NOT_EMPTY).build(); } else { log.debug("DeleteScope failed due to {} ", ex); return DeleteScopeStatus.newBuilder().setStatus(DeleteScopeStatus.Status.FAILURE).build(); } }); }
@Test public void testZkDeleteScope() throws Exception { // create new scope final StreamMetadataStore store = new ZKStreamMetadataStore(cli, executor); final String scopeName = "Scope1"; store.createScope(scopeName).get(); // Delete empty scope Scope1 CompletableFuture<DeleteScopeStatus> deleteScopeStatus = store.deleteScope(scopeName); assertEquals("Delete Empty Scope", DeleteScopeStatus.Status.SUCCESS, deleteScopeStatus.get().getStatus()); // Delete non-existent scope Scope2 CompletableFuture<DeleteScopeStatus> deleteScopeStatus2 = store.deleteScope("Scope2"); assertEquals("Delete non-existent Scope", DeleteScopeStatus.Status.SCOPE_NOT_FOUND, deleteScopeStatus2.get().getStatus()); // Delete non-empty scope Scope3 store.createScope("Scope3").get(); final ScalingPolicy policy = ScalingPolicy.fixed(5); final StreamConfiguration streamConfig = StreamConfiguration.builder().scalingPolicy(policy).build(); store.createStream("Scope3", "Stream3", streamConfig, System.currentTimeMillis(), null, executor).get(); store.setState("Scope3", "Stream3", State.ACTIVE, null, executor).get(); CompletableFuture<DeleteScopeStatus> deleteScopeStatus3 = store.deleteScope("Scope3"); assertEquals("Delete non-empty Scope", DeleteScopeStatus.Status.SCOPE_NOT_EMPTY, deleteScopeStatus3.get().getStatus()); }
@Override public CompletableFuture<Boolean> deleteScope(String scopeName) { return this.controller.deleteScope(scopeName).thenApply(x -> { switch (x.getStatus()) { case FAILURE: throw new ControllerFailureException("Failed to delete scope: " + scopeName); case SCOPE_NOT_EMPTY: throw new IllegalStateException("Scope " + scopeName + " is not empty."); case SCOPE_NOT_FOUND: return false; case SUCCESS: return true; default: throw new ControllerFailureException("Unknown return status deleting scope " + scopeName + " " + x.getStatus()); } }); }
@Test public void deleteTest() throws Exception { final String scope = "ScopeDelete"; final String stream = "StreamDelete"; final ScalingPolicy policy = ScalingPolicy.fixed(2); final StreamConfiguration configuration = StreamConfiguration.builder().scalingPolicy(policy).build(); long start = System.currentTimeMillis(); store.createScope(scope).get(); store.createStream(scope, stream, configuration, start, null, executor).get(); store.setState(scope, stream, State.ACTIVE, null, executor).get(); assertTrue(store.checkStreamExists(scope, stream).join()); store.deleteStream(scope, stream, null, executor).get(); assertFalse(store.checkStreamExists(scope, stream).join()); DeleteScopeStatus status = store.deleteScope(scope).join(); assertEquals(status.getStatus(), DeleteScopeStatus.Status.SUCCESS); }
public Builder newBuilderForType() { return newBuilder(); } public static Builder newBuilder() {
public io.pravega.controller.stream.api.grpc.v1.Controller.DeleteScopeStatus getDefaultInstanceForType() { return io.pravega.controller.stream.api.grpc.v1.Controller.DeleteScopeStatus.getDefaultInstance(); }
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); hash = (37 * hash) + STATUS_FIELD_NUMBER; hash = (53 * hash) + status_; hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
public io.pravega.controller.stream.api.grpc.v1.Controller.DeleteScopeStatus buildPartial() { io.pravega.controller.stream.api.grpc.v1.Controller.DeleteScopeStatus result = new io.pravega.controller.stream.api.grpc.v1.Controller.DeleteScopeStatus(this); result.status_ = status_; onBuilt(); return result; }
public io.pravega.controller.stream.api.grpc.v1.Controller.DeleteScopeStatus build() { io.pravega.controller.stream.api.grpc.v1.Controller.DeleteScopeStatus result = buildPartial(); if (!result.isInitialized()) { throw newUninitializedMessageException(result); } return result; }
public Builder mergeFrom(io.pravega.controller.stream.api.grpc.v1.Controller.DeleteScopeStatus other) { if (other == io.pravega.controller.stream.api.grpc.v1.Controller.DeleteScopeStatus.getDefaultInstance()) return this; if (other.status_ != 0) { setStatusValue(other.getStatusValue()); } this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }