/** * Creates a new exception with the failure message from the result. * * @param message the message to prepend to the failure message * @param operation the operation which failed * @param result the result of the operation */ public OperationExecutionException(final String message, final Operation operation, final ModelNode result) { this(message, operation.getOperation(), result); }
@Override public ModelNode execute(Operation operation) throws IOException { if (!operation.getInputStreams().isEmpty()) { throw new IllegalStateException("Operation has one or more attachments which is not allowed."); } return execute(operation.getOperation()); }
private Operation sanitizeOperation(Operation operation) { ModelNode sanitized = sanitizeOperation(operation.getOperation()); return Operation.Factory.create(sanitized, operation.getInputStreams(), operation.isAutoCloseStreams()); }
static List<InputStreamEntry> createStreamEntries(final Operation operation) { final List<InputStream> streams = operation.getInputStreams(); if(streams.isEmpty()) { return Collections.emptyList(); } final List<InputStreamEntry> entries = new ArrayList<InputStreamEntry>(); final boolean autoClose = operation.isAutoCloseStreams(); for(final InputStream stream : streams) { if(stream instanceof InputStreamEntry) { entries.add((InputStreamEntry) stream); } else { // TODO don't copy everything to memory... perhaps use InputStreamEntry.CachingStreamEntry entries.add(new InputStreamEntry.InMemoryEntry(stream, autoClose)); } } return entries; }
private void closeAttachments() { for(final InputStreamEntry entry : streams) { StreamUtils.safeClose(entry); } if(operation.isAutoCloseStreams()) { StreamUtils.safeClose(operation); } }
static List<InputStreamEntry> createStreamEntries(final Operation operation) { final List<InputStream> streams = operation.getInputStreams(); if(streams.isEmpty()) { return Collections.emptyList(); } final List<InputStreamEntry> entries = new ArrayList<InputStreamEntry>(); final boolean autoClose = operation.isAutoCloseStreams(); for(final InputStream stream : streams) { if(stream instanceof InputStreamEntry) { entries.add((InputStreamEntry) stream); } else { // TODO don't copy everything to memory... perhaps use InputStreamEntry.CachingStreamEntry entries.add(new InputStreamEntry.InMemoryEntry(stream, autoClose)); } } return entries; }
private void closeAttachments() { for(final InputStreamEntry entry : streams) { StreamUtils.safeClose(entry); } if(operation.isAutoCloseStreams()) { StreamUtils.safeClose(operation); } }
private static void executeProcess(Operation command, String database) throws IOException, InterruptedException { final File executorDirectory = new File("src/main/resources/"); private final static String shellScript = "./sparksubmit.sh"; ProcessBuilder processBuilder = new ProcessBuilder(shellScript, command.getOperation(), "argument-one"); processBuilder.directory(executorDirectory); Process process = processBuilder.start(); try { int shellExitStatus = process.waitFor(); if (shellExitStatus != 0) { logger.info("Successfully executed the shell script"); } } catch (InterruptedException ex) { logger.error("Shell Script process was interrupted"); } }
@Override protected void sendRequest(final ActiveOperation.ResultHandler<ModelNode> resultHandler, final ManagementRequestContext<OperationExecutionContext> context, final FlushableDataOutput output) throws IOException { // Write the operation final List<InputStream> streams = executionContext.operation.getInputStreams(); final ModelNode operation = executionContext.operation.getOperation(); int inputStreamLength = 0; if (streams != null) { inputStreamLength = streams.size(); } output.write(ModelControllerProtocol.PARAM_OPERATION); operation.writeExternal(output); output.write(ModelControllerProtocol.PARAM_INPUTSTREAMS_LENGTH); output.writeInt(inputStreamLength); }
private Operation sanitizeOperation(Operation operation) { ModelNode sanitized = sanitizeOperation(operation.getOperation()); return Operation.Factory.create(sanitized, operation.getInputStreams(), operation.isAutoCloseStreams()); }
} finally { if (builtOp.isAutoCloseStreams()) { for (InputStream in : builtOp.getInputStreams()) { IoUtils.safeClose(in);
/** @return always the {@code operation} object itself, possibly modified */ Operation adjust(Operation operation) { if (!options.isDomain) { return operation; } // this relies on an assumption that Operation.getOperation always returns the underlying ModelNode // and not a copy (see also ControllerClientAssumptionTest) adjust(operation.getOperation()); return operation; }
@Override protected void sendRequest(final ActiveOperation.ResultHandler<OperationResponse> resultHandler, final ManagementRequestContext<OperationExecutionContext> context, final FlushableDataOutput output) throws IOException { // Write the operation final List<InputStream> streams = executionContext.operation.getInputStreams(); final ModelNode operation = executionContext.operation.getOperation(); int inputStreamLength = 0; if (streams != null) { inputStreamLength = streams.size(); } output.write(ModelControllerProtocol.PARAM_OPERATION); operation.writeExternal(output); output.write(ModelControllerProtocol.PARAM_INPUTSTREAMS_LENGTH); output.writeInt(inputStreamLength); }
@Override public ModelNode execute(Operation operation, OperationMessageHandler messageHandler) throws IOException { return ModelControllerImpl.this.execute(operation.getOperation(), messageHandler, OperationTransactionControl.COMMIT, operation); }
@Override protected OperationResponse internalExecute(final Operation operation, final ManagementRequestContext<?> context, final OperationMessageHandler messageHandler, final ModelController.OperationTransactionControl control) { final ModelNode operationNode = operation.getOperation(); final OperationStepHandler handler; final String operationName = operation.getOperation().require(OP).asString(); if (operationName.equals(FetchMissingConfigurationHandler.OPERATION_NAME)) { handler = new FetchMissingConfigurationHandler(SlaveChannelAttachments.getHostName(context.getChannel()), assert operation.getInputStreams().size() == 0; // we don't support associating streams with an active op ModelNode responseNode = executor.joinActiveOperation(operation.getOperation(), messageHandler, control, handler, domainControllerLockId); return OperationResponse.Factory.createSimple(responseNode); } else {
@Override public AsyncFuture<ModelNode> executeAsync(final Operation operation, final OperationMessageHandler messageHandler) { return executeAsync(operation.getOperation(), messageHandler, operation); }
@Override protected OperationResponse internalExecute(final Operation operation, final ManagementRequestContext<?> context, final OperationMessageHandler messageHandler, final ModelController.OperationTransactionControl control) { final ModelNode operationNode = operation.getOperation(); final OperationStepHandler handler; final String operationName = operation.getOperation().require(OP).asString(); if (operationName.equals(FetchMissingConfigurationHandler.OPERATION_NAME)) { handler = new FetchMissingConfigurationHandler(SlaveChannelAttachments.getHostName(context.getChannel()), assert operation.getInputStreams().size() == 0; // we don't support associating streams with an active op ModelNode responseNode = executor.joinActiveOperation(operation.getOperation(), messageHandler, control, handler, domainControllerLockId); return OperationResponse.Factory.createSimple(responseNode); } else {
protected OperationResponse internalExecute(final Operation operation, final OperationMessageHandler handler, final ModelController.OperationTransactionControl control, final OperationStepHandler prepareStep, final boolean attemptLock, final boolean partialModel) { return controller.internalExecute(operation.getOperation(), handler, control, operation, prepareStep, attemptLock, partialModel); }
@Override public AsyncFuture<ModelNode> executeAsync(final Operation operation, final OperationMessageHandler messageHandler) { return executeAsync(operation.getOperation(), messageHandler, operation, ResponseConverter.TO_MODEL_NODE); }
@Override public AsyncFuture<OperationResponse> executeOperationAsync(Operation operation, OperationMessageHandler messageHandler) { return executeAsync(operation.getOperation(), messageHandler, operation, ResponseConverter.TO_OPERATION_RESPONSE); }