Skip to content

Commit

Permalink
Merge pull request #37 from ppalaga/HAWKULAR-517
Browse files Browse the repository at this point in the history
HAWKULAR-517 Create and Manage JDBC Drivers
  • Loading branch information
jmazzitelli committed Sep 4, 2015
2 parents 0c90cbb + 5d09a01 commit 4ad4ce3
Show file tree
Hide file tree
Showing 9 changed files with 272 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"definitions": {
"authentication": {
"type": "object",
"description": "Provides user credentials or security token.",
"description": "Provides user credentials or security token. The awkward name is there so that this schema file precedes all other schema files alphabetically. This is required by jsonschema2pojo-maven-plugin that is not resolving the inter-schema dependencies, it just takes files in alphabetical order.",
"additionalProperties": false,
"properties": {
"username": { "type": "string" },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"type": "object",
"extends": {
"type": "object",
"javaType": "org.hawkular.feedcomm.api.AuthMessage"
},
"javaType": "org.hawkular.feedcomm.api.AddJdbcDriverRequest",
"description": "Adds a JDBC Driver to a resource. The driver module is created only if driverJarName is set (in such a case, the jar file content must be appended to this JSON message). Otherwise, the existence of the module given by moduleName and default slot \"main\" will be assumed.",
"additionalProperties": false,
"properties": {
"resourcePath": {
"description" : "The inventory path to the resource that is to deploy the application",
"type": "string"
},
"driverName": {
"type": "string"
},
"moduleName": {
"description": "The name of the JBoss Module to create or use, such as \"org.example.jdbc.driver\"",
"type": "string"
},
"driverJarName": {
"description": "The name of the jar file that should be used when storing the binary data to in the module directory on the server. If this field is set the jar bits must be appended to this JSON message. If this field is set, the module will be created, otherwise the existence of the module given by moduleName and default slot \"main\" will be assumed.",
"type": "string"
}
},
"required": ["resourcePath", "driverName", "moduleName"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"type": "object",
"extends": {
"type": "object",
"javaType": "org.hawkular.feedcomm.api.AuthMessage"
},
"javaType": "org.hawkular.feedcomm.api.AddJdbcDriverResponse",
"description": "Results of an Add Driver request.",
"additionalProperties": false,
"properties": {
"resourcePath": {
"description" : "The inventory path to the resource that is to deploy the application",
"type": "string"
},
"status": {
"type": "string",
"description": "Indicates if the deployment succeeded or failed."
},
"message": {
"type": "string",
"description": "A message that further describes the results of the deployment."
}
},
"required": ["resourcePath", "status"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.hawkular.feedcomm.ws.command.GenericErrorResponseCommand;
import org.hawkular.feedcomm.ws.command.feed.DeployApplicationResponseCommand;
import org.hawkular.feedcomm.ws.command.feed.ExecuteOperationResponseCommand;
import org.hawkular.feedcomm.ws.command.ui.AddJdbcDriverCommand;
import org.hawkular.feedcomm.ws.command.ui.DeployApplicationCommand;
import org.hawkular.feedcomm.ws.command.ui.ExecuteOperationCommand;
import org.hawkular.feedcomm.ws.server.ValidCommandsMap;
Expand Down Expand Up @@ -61,14 +62,17 @@ public interface Constants {
ValidCommandsMap VALID_COMMANDS_FROM_UI = new ValidCommandsMap()
.put(EchoCommand.REQUEST_CLASS.getName(), EchoCommand.class)
.put(DeployApplicationCommand.REQUEST_CLASS.getName(), DeployApplicationCommand.class)
.put(AddJdbcDriverCommand.REQUEST_CLASS.getName(), AddJdbcDriverCommand.class)
.put(ExecuteOperationCommand.REQUEST_CLASS.getName(), ExecuteOperationCommand.class)
.put(GenericErrorResponseCommand.REQUEST_CLASS.getName(), GenericErrorResponseCommand.class);

// QUEUES AND TOPICS
Endpoint DEST_FEED_EXECUTE_OP = new Endpoint(Type.QUEUE, "FeedExecuteOperation");
Endpoint DEST_FEED_DEPLOY_APPLICATION = new Endpoint(Type.QUEUE, "FeedDeployApplication");
Endpoint DEST_FEED_ADD_JDBC_DRIVER = new Endpoint(Type.QUEUE, "FeedAddJdbcDriver");

Endpoint DEST_UICLIENT_EXECUTE_OP_RESPONSE = new Endpoint(Type.QUEUE, "UIClientExecuteOperationResponse");
Endpoint DEST_UICLIENT_DEPLOY_APPLICATION_RESPONSE = new Endpoint(Type.QUEUE, "UIDeployApplicationResponse");
Endpoint DEST_UICLIENT_ADD_JDBC_DRIVER_RESPONSE = new Endpoint(Type.QUEUE, "UIAddJdbcDriverResponse");

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2015 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hawkular.feedcomm.ws.command.ui;

import java.util.Collections;
import java.util.Map;

import org.hawkular.bus.common.BinaryData;
import org.hawkular.bus.common.ConnectionContextFactory;
import org.hawkular.bus.common.Endpoint;
import org.hawkular.bus.common.MessageId;
import org.hawkular.bus.common.MessageProcessor;
import org.hawkular.bus.common.producer.ProducerConnectionContext;
import org.hawkular.feedcomm.api.AddJdbcDriverRequest;
import org.hawkular.feedcomm.api.GenericSuccessResponse;
import org.hawkular.feedcomm.ws.Constants;
import org.hawkular.feedcomm.ws.MsgLogger;
import org.hawkular.feedcomm.ws.command.Command;
import org.hawkular.feedcomm.ws.command.CommandContext;
import org.hawkular.inventory.api.model.CanonicalPath;

/**
* UI client requesting to send a file to a remote feed.
*/
public class AddJdbcDriverCommand implements Command<AddJdbcDriverRequest, GenericSuccessResponse> {
public static final Class<AddJdbcDriverRequest> REQUEST_CLASS = AddJdbcDriverRequest.class;

@Override
public GenericSuccessResponse execute(AddJdbcDriverRequest request, BinaryData binaryData,
CommandContext context) throws Exception {

// determine what feed needs to be sent the message
CanonicalPath resourcePath = CanonicalPath.fromString(request.getResourcePath());
String feedId = resourcePath.ids().getFeedId();

try (ConnectionContextFactory ccf = new ConnectionContextFactory(context.getConnectionFactory())) {
Endpoint endpoint = Constants.DEST_FEED_ADD_JDBC_DRIVER;
ProducerConnectionContext pcc = ccf.createProducerConnectionContext(endpoint);
Map<String, String> feedIdHeader = Collections.singletonMap(Constants.HEADER_FEEDID, feedId);
MessageId mid = new MessageProcessor().sendWithBinaryData(pcc, request, binaryData, feedIdHeader);
MsgLogger.LOG.debugf("File upload request placed on bus. mid=[%s], request=[%s]", mid, request);
GenericSuccessResponse response = new GenericSuccessResponse();
response.setMessage("The execution request has been forwarded to feed [" + feedId + "] (id=" + mid + ")");
return response;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright 2015 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hawkular.feedcomm.ws.mdb;

import java.util.concurrent.ExecutorService;

import javax.websocket.Session;

import org.hawkular.bus.common.BasicMessageWithExtraData;
import org.hawkular.bus.common.BinaryData;
import org.hawkular.bus.common.consumer.BasicMessageListener;
import org.hawkular.feedcomm.api.AddJdbcDriverRequest;
import org.hawkular.feedcomm.api.ApiDeserializer;
import org.hawkular.feedcomm.ws.Constants;
import org.hawkular.feedcomm.ws.MsgLogger;
import org.hawkular.feedcomm.ws.WebSocketHelper;
import org.hawkular.feedcomm.ws.server.ConnectedFeeds;

public class AddJdbcDriverListener extends BasicMessageListener<AddJdbcDriverRequest> {

private final ConnectedFeeds connectedFeeds;
private final ExecutorService threadPool;

public AddJdbcDriverListener(ConnectedFeeds connectedFeeds, ExecutorService threadPool) {
this.connectedFeeds = connectedFeeds;
this.threadPool = threadPool;
}

protected void onBasicMessage(BasicMessageWithExtraData<AddJdbcDriverRequest> request) {
try {
AddJdbcDriverRequest basicMessage = request.getBasicMessage();
String feedId = basicMessage.getHeaders().get(Constants.HEADER_FEEDID);
if (feedId == null) {
throw new IllegalArgumentException("Missing header: " + Constants.HEADER_FEEDID);
}
Session session = connectedFeeds.getSession(feedId);
if (session == null) {
return; // we don't have the feed, this message isn't for us
}

MsgLogger.LOG.infof("Sending feed [%s] an JDBC Driver add on resource [%s]", feedId,
basicMessage.getResourcePath());

// send the request to the feed
BinaryData dataToSend = ApiDeserializer.toHawkularFormat(basicMessage, request.getBinaryData());
new WebSocketHelper().sendBinaryAsync(session, dataToSend, threadPool);
return;

} catch (Exception e) {
// catch all exceptions and just log the error to let us auto-ack the message anyway
MsgLogger.LOG.errorf(e, "Cannot process deploy application request");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright 2015 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hawkular.feedcomm.ws.mdb;

import javax.websocket.Session;

import org.hawkular.bus.common.BasicMessageWithExtraData;
import org.hawkular.bus.common.consumer.BasicMessageListener;
import org.hawkular.feedcomm.api.AddJdbcDriverResponse;
import org.hawkular.feedcomm.ws.Constants;
import org.hawkular.feedcomm.ws.MsgLogger;
import org.hawkular.feedcomm.ws.WebSocketHelper;
import org.hawkular.feedcomm.ws.server.ConnectedUIClients;

public class AddJdbcDriverResponseListener extends BasicMessageListener<AddJdbcDriverResponse> {

private ConnectedUIClients connectedUIClients;

public AddJdbcDriverResponseListener(ConnectedUIClients connectedUIClients) {
this.connectedUIClients = connectedUIClients;
}

protected void onBasicMessage(BasicMessageWithExtraData<AddJdbcDriverResponse> responseWithData) {
try {
AddJdbcDriverResponse response = responseWithData.getBasicMessage();
String uiClientId = response.getHeaders().get(Constants.HEADER_UICLIENTID);
if (uiClientId == null) {
// TODO: for now, just send it to all UI clients on our server (we don't really want this behavior)
// we really want to those this exception since in the future the header must be there
//throw new IllegalArgumentException("Missing header: " + Constants.HEADER_UICLIENTID);
MsgLogger.LOG.warnf(
"HACK: Telling ALL UI that JDBC Driver add on resource [%s] resulted in [%s][%s]",
response.getResourcePath(), response.getStatus(),
response.getMessage());
new WebSocketHelper().sendBasicMessageAsync(connectedUIClients.getAllSessions(), response);
return;
}

// we are assuming the UI client ID *is* the session ID
Session session = connectedUIClients.getSessionBySessionId(uiClientId);
if (session == null) {
return; // we don't have the UI client, this message isn't for us
}

MsgLogger.LOG.infof(
"Telling UI client [%s] that that JDBC Driver add on resource [%s] resulted in [%s][%s]",
uiClientId, response.getResourcePath(), response.getStatus(),
response.getMessage());

// send the request to the UI client
new WebSocketHelper().sendBasicMessageAsync(session, response);
return;

} catch (Exception e) {
// catch all exceptions and just log the error to let us auto-ack the message anyway
MsgLogger.LOG.errorf(e, "Cannot process AddJdbcDriverResponse message");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.hawkular.bus.common.consumer.ConsumerConnectionContext;
import org.hawkular.feedcomm.ws.Constants;
import org.hawkular.feedcomm.ws.MsgLogger;
import org.hawkular.feedcomm.ws.mdb.AddJdbcDriverListener;
import org.hawkular.feedcomm.ws.mdb.DeployApplicationListener;
import org.hawkular.feedcomm.ws.mdb.ExecuteOperationListener;

Expand Down Expand Up @@ -113,6 +114,11 @@ public void addListeners(String feedId) throws Exception {
messageProcessor.listen(ccc, new DeployApplicationListener(connectedFeeds, threadPoolService));
contextList.add(ccc);

endpoint = Constants.DEST_FEED_ADD_JDBC_DRIVER;
ccc = ccf.createConsumerConnectionContext(endpoint, messageSelector);
messageProcessor.listen(ccc, new AddJdbcDriverListener(connectedFeeds, threadPoolService));
contextList.add(ccc);

return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.hawkular.bus.common.consumer.ConsumerConnectionContext;
import org.hawkular.feedcomm.ws.Constants;
import org.hawkular.feedcomm.ws.MsgLogger;
import org.hawkular.feedcomm.ws.mdb.AddJdbcDriverResponseListener;
import org.hawkular.feedcomm.ws.mdb.DeployApplicationResponseListener;
import org.hawkular.feedcomm.ws.mdb.ExecuteOperationResponseListener;

Expand Down Expand Up @@ -111,18 +112,18 @@ public void addListeners(String uiClientId) throws Exception {
ccc = ccf.createConsumerConnectionContext(endpoint, null);
messageProcessor.listen(ccc, new DeployApplicationResponseListener(connectedUIClients));
contextList.add(ccc);

endpoint = Constants.DEST_UICLIENT_ADD_JDBC_DRIVER_RESPONSE;
ccc = ccf.createConsumerConnectionContext(endpoint, null);
messageProcessor.listen(ccc, new AddJdbcDriverResponseListener(connectedUIClients));
contextList.add(ccc);
}

Endpoint endpoint = Constants.DEST_UICLIENT_EXECUTE_OP_RESPONSE;
ConsumerConnectionContext ccc = ccf.createConsumerConnectionContext(endpoint, messageSelector);
messageProcessor.listen(ccc, new ExecuteOperationResponseListener(connectedUIClients));
contextList.add(ccc);

endpoint = Constants.DEST_UICLIENT_DEPLOY_APPLICATION_RESPONSE;
ccc = ccf.createConsumerConnectionContext(endpoint, null);
messageProcessor.listen(ccc, new DeployApplicationResponseListener(connectedUIClients));
contextList.add(ccc);

return;
}

Expand Down

0 comments on commit 4ad4ce3

Please sign in to comment.