-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from ppalaga/HAWKULAR-517
HAWKULAR-517 Create and Manage JDBC Drivers
- Loading branch information
Showing
9 changed files
with
272 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
hawkular-feed-comm/feed-comm-api/src/main/resources/schema/AddJdbcDriverRequest.schema.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
25 changes: 25 additions & 0 deletions
25
hawkular-feed-comm/feed-comm-api/src/main/resources/schema/AddJdbcDriverResponse.schema.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...feed-comm-war/src/main/java/org/hawkular/feedcomm/ws/command/ui/AddJdbcDriverCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...-comm/feed-comm-war/src/main/java/org/hawkular/feedcomm/ws/mdb/AddJdbcDriverListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...ed-comm-war/src/main/java/org/hawkular/feedcomm/ws/mdb/AddJdbcDriverResponseListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters