@Override protected void success( BasicMessageWithExtraData<AddDatasourceRequest> envelope, AddDatasourceResponse response) { response.setStatus(ResponseStatus.OK); response.setMessage( String.format("Added Datasource: %s", envelope.getBasicMessage().getDatasourceName())); }
@Override protected BinaryData execute( ModelControllerClient controllerClient, EndpointService<DMRNodeLocation, DMRSession> // endpointService, String modelNodePath, BasicMessageWithExtraData<AddDatasourceRequest> envelope, AddDatasourceResponse response, CommandContext context, DMRSession dmrContext) throws Exception { AddDatasourceRequest request = envelope.getBasicMessage(); response.setDatasourceName(request.getDatasourceName()); response.setXaDatasource(request.isXaDatasource()); Map<String, String> props = request.getDatasourceProperties(); final String dsDmrResourceType; final String dsPropsDmrResourceType; final ModelNode dsAdr; final CompositeOperationBuilder<?> batch; if (request.isXaDatasource()) { dsDmrResourceType = XA_DATASOURCE; dsPropsDmrResourceType = XA_DATASOURCE_PROPERTIES; dsAdr = OperationBuilder.address() .subsystemDatasources() .segment(dsDmrResourceType, request.getDatasourceName()) .build(); batch = OperationBuilder.composite() // .add() // .address(dsAdr) // .attribute(JNDI_NAME, request.getJndiName()) // .attribute(DRIVER_NAME, request.getDriverName()) // .attribute(XA_DATASOURCE_CLASS, request.getXaDataSourceClass()) // .attribute(USER_NAME, request.getUserName()) // .attribute(PASSWORD, request.getPassword()) // .parentBuilder(); } else { dsDmrResourceType = DATASOURCE; dsPropsDmrResourceType = CONNECTION_PROPERTIES; dsAdr = OperationBuilder.address() .subsystemDatasources() .segment(dsDmrResourceType, request.getDatasourceName()) .build(); batch = OperationBuilder.composite() // .add() // .address(dsAdr) // .attribute(JNDI_NAME, request.getJndiName()) // .attribute(DRIVER_NAME, request.getDriverName()) // .attribute(DRIVER_CLASS, request.getDriverClass()) // .attribute(CONNECTION_URL, request.getConnectionUrl()) // .attribute(USER_NAME, request.getUserName()) // .attribute(PASSWORD, request.getPassword()) // .parentBuilder(); } if (!props.isEmpty()) { for (Entry<String, String> prop : props.entrySet()) { batch .add() // .address() .segments(dsAdr) .segment(dsPropsDmrResourceType, prop.getKey()) .parentBuilder() // .attribute(ModelDescriptionConstants.VALUE, prop.getValue()) .parentBuilder(); } } batch.execute(controllerClient).assertSuccess(); // TODO replace with endpointService.discoverChildren(parentLocation, childType) endpointService.discoverAll(); return null; }