io.vertx.core.cli.CLIException Java Examples
The following examples show how to use
io.vertx.core.cli.CLIException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KonduitRunCommand.java From konduit-serving with Apache License 2.0 | 5 votes |
@Override @Option(longName = "service", shortName = "s", argName = "type") @DefaultValue(DEFAULT_SERVICE) @Description("Service type that needs to be deployed. Defaults to \"inference\"") public void setMainVerticle(String konduitServiceType) { if(getServicesMap().containsKey(konduitServiceType)) { super.setMainVerticle(KONDUIT_PREFIX + ":" + konduitServiceType); } else { throw new CLIException(String.format("Invalid service type %s. " + "Allowed values are: %s", konduitServiceType, Collections.singletonList(getServicesMap().keySet()))); } }
Example #2
Source File: InspectCommand.java From konduit-serving with Apache License 2.0 | 5 votes |
@Override public void run() throws CLIException { if(LauncherUtils.isProcessExists(id)) { try { out.format("\nKonduit server with the id '%s' is initialized with the following configuration: \n\n%s\n\n", id, FileUtils.readFileToString(new File(DirectoryFetcher.getServersDataDir(), LauncherUtils.getPidFromServerId(id) + ".data"), StandardCharsets.UTF_8)); } catch (Exception exception) { log.error("Failed to read configuration file", exception); } } else { out.println("No konduit server exists with an id: " + id); } }
Example #3
Source File: KonduitRunCommand.java From konduit-serving with Apache License 2.0 | 5 votes |
@Override @Option(longName = "service", shortName = "s", argName = "service-type") @DefaultValue(DEFAULT_SERVICE) @Description("Service type that needs to be deployed. Defaults to '" + DEFAULT_SERVICE + "'") public void setMainVerticle(String serviceType) { if(VALID_SERVICE_TYPES.contains(serviceType)) { this.serviceType = serviceType; } else { throw new CLIException( String.format("Invalid service type %s. Allowed values are: %s", serviceType, VALID_SERVICE_TYPES) ); } }
Example #4
Source File: KonduitRunCommand.java From konduit-serving with Apache License 2.0 | 5 votes |
@Override protected void deploy() { if (INFERENCE_SERVICE_TYPE_NAME.equalsIgnoreCase(serviceType)) { DeployKonduitServing.registerInferenceVerticleFactory(vertx); super.setMainVerticle(INFERENCE_SERVICE_IDENTIFIER + ":" + inferenceConfiguration.protocol().name().toLowerCase()); } else { throw new CLIException(String.format("Unsupported service type %s", serviceType)); } deploy(mainVerticle, vertx, deploymentOptions, res -> {}); }
Example #5
Source File: PredictCommand.java From konduit-serving with Apache License 2.0 | 4 votes |
@Override public void run() { if(LauncherUtils.isProcessExists(id)) { Vertx vertx = Vertx.vertx(); try { InferenceConfiguration inferenceConfiguration = InferenceConfiguration.fromJson( FileUtils.readFileToString(new File(DirectoryFetcher.getServersDataDir(), getPidFromServerId(id) + ".data"), StandardCharsets.UTF_8)); switch (protocol) { case HTTP: String contentType; if(inputType.contains("json")) { contentType = APPLICATION_JSON.toString(); } else { contentType = APPLICATION_OCTET_STREAM.toString(); } String accept; if(outputType.contains("json")) { accept = APPLICATION_JSON.toString(); } else { accept = APPLICATION_OCTET_STREAM.toString(); } HttpRequest<Buffer> request = WebClient.create(vertx) .head(inferenceConfiguration.port(), inferenceConfiguration.host(), "/predict") .putHeader(CONTENT_TYPE.toString(), contentType) .putHeader(ACCEPT.toString(), accept) .method(HttpMethod.POST); Handler<AsyncResult<HttpResponse<Buffer>>> responseHandler = handler -> { if(handler.succeeded()) { HttpResponse<Buffer> httpResponse = handler.result(); int statusCode = httpResponse.statusCode(); if(statusCode == 200) { out.print(handler.result().body()); } else { out.format("Request failed with status code: %s%nDetails: %s%n", statusCode, handler.result().bodyAsString()); } } else { out.format("Failed request.%nExecute '%s logs %s' to find the cause.%n", ((KonduitServingLauncher) executionContext.launcher()).commandLinePrefix(), id); } vertx.close(); }; if (inputType.contains("file")) { request.sendBuffer(Buffer.buffer(FileUtils.readFileToByteArray(new File(data))), responseHandler); } else { request.sendBuffer(Buffer.buffer(data.getBytes()), responseHandler); } break; case GRPC: if (!VALID_GRPC_INPUT_TYPES.contains(inputType)) { out.format("Invalid input type %s for gRPC protocol valid input types are %s%n", inputType, VALID_GRPC_INPUT_TYPES); System.exit(1); } if(!VALID_GRPC_OUTPUT_TYPES.contains(outputType)) { out.format("Invalid output type %s for gRPC protocol valid output types are %s%n", outputType, VALID_GRPC_OUTPUT_TYPES); System.exit(1); } InferenceGrpc.newVertxStub(VertxChannelBuilder .forAddress(vertx, inferenceConfiguration.host(), inferenceConfiguration.port()) .usePlaintext(true) .build()) .predict(DataProtoMessage.DataScheme.parseFrom( inputType.contains("file") ? FileUtils.readFileToByteArray(new File(data)) : data.getBytes()), ar -> { if (ar.succeeded()) { out.print(new String(ar.result().toByteArray())); } else { ar.cause().printStackTrace(out); } vertx.close(); }); break; case MQTT: default: throw new CLIException(String.format("Unsupported protocol: %s", protocol)); } } catch (Exception exception) { exception.printStackTrace(out); vertx.close(); } } else { out.println("No konduit server exists with an id: " + id); } }
Example #6
Source File: ApimanVersionCommand.java From apiman with Apache License 2.0 | 4 votes |
@Override public void run() throws CLIException { log.info("Apiman " + getApimanVersion()); log.info("Vert.x " + VersionCommand.getVersion()); }