Skip to content

Commit

Permalink
Simplify the API
Browse files Browse the repository at this point in the history
  • Loading branch information
ppalaga committed Sep 30, 2015
1 parent 5de5da5 commit 8c4ae14
Show file tree
Hide file tree
Showing 76 changed files with 2,035 additions and 3,062 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.IOException;
import java.io.InputStream;

import org.hawkular.bus.common.AbstractMessage;
import org.hawkular.bus.common.BasicMessage;
import org.hawkular.bus.common.BasicMessageWithExtraData;
import org.hawkular.bus.common.BinaryData;
Expand Down Expand Up @@ -79,7 +80,7 @@ public ApiDeserializer() {
* @param nameAndJson the string to be deserialized
* @return the object represented by the JSON
*/
public <T extends BasicMessage> T deserialize(String nameAndJson) {
public <T extends BasicMessage> BasicMessageWithExtraData<T> deserialize(String nameAndJson) {
String[] nameAndJsonArray = fromHawkularFormat(nameAndJson);
String name = nameAndJsonArray[0];
String json = nameAndJsonArray[1];
Expand All @@ -92,7 +93,7 @@ public <T extends BasicMessage> T deserialize(String nameAndJson) {

try {
Class<T> pojo = (Class<T>) Class.forName(name);
return BasicMessage.fromJSON(json, pojo);
return new BasicMessageWithExtraData(AbstractMessage.fromJSON(json, pojo), null);
} catch (Exception e) {
throw new RuntimeException("Cannot deserialize: [" + nameAndJson + "]", e);
}
Expand Down Expand Up @@ -146,7 +147,7 @@ public <T extends BasicMessage> BasicMessageWithExtraData<T> deserialize(InputSt
// We now have the name and the input stream is pointing at the JSON
try {
Class<T> pojo = (Class<T>) Class.forName(name);
BasicMessageWithExtraData<T> results = BasicMessage.fromJSON(input, pojo);
BasicMessageWithExtraData<T> results = AbstractMessage.fromJSON(input, pojo);
return results;
} catch (Exception e) {
throw new RuntimeException("Cannot deserialize stream with object [" + name + "]", e);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.cmdgw.api;

/**
* @author <a href="https://github.com/ppalaga">Peter Palaga</a>
*/
public class MessageUtils {
public static void prepareResourcePathResponse(ResourcePathRequest request, ResourcePathResponse response) {
prepareUiSessionDestination((UiSessionOrigin) request, (UiSessionDestination) response);
response.setResourcePath(request.getResourcePath());
}
public static void prepareUiSessionDestination(UiSessionOrigin request, UiSessionDestination response) {
response.setDestinationSessionId(request.getSenderSessionId());
response.setSenderRequestId(request.getSenderRequestId());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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.cmdgw.api;

import org.hawkular.bus.common.BasicMessage;

/**
* @author <a href="https://github.com/ppalaga">Peter Palaga</a>
*/
public interface ResourcePathDestination extends BasicMessage {
String getResourcePath();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.cmdgw.api;

import org.hawkular.bus.common.BasicMessage;

/**
* @author <a href="https://github.com/ppalaga">Peter Palaga</a>
*/
public interface UiSessionDestination extends BasicMessage {
/**
* @return an ID chosen originally by the sending UI client that should make it possible to associate this response
* with the triggering request. This ID is supposed to be unique just within the sending WebSocket session.
*/
String getSenderRequestId();
void setSenderRequestId(String requestId);

/**
* @return the ID of a WebSocket Session that is the destination of this message.
*/
String getDestinationSessionId();
void setDestinationSessionId(String sessionId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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.cmdgw.api;

import org.hawkular.bus.common.BasicMessage;

/**
* @author <a href="https://github.com/ppalaga">Peter Palaga</a>
*/
public interface UiSessionOrigin extends BasicMessage {
String getSenderRequestId();
String getSenderSessionId();
void setSenderSessionId(String sessionId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"definitions": {
"authentication": {
"type": "object",
"description": "Provides user credentials or security token. The awkward name of the schema file A0AuthMessage.schema.json 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" },
"password": { "type": "string" },
"token": { "type": "string" },
"persona": { "type": "string" }
}
},
"recipientType": {
"type": "object",
"description": "A binary attachment metadata",
"enum": ["UI", "resource"]
},
"attachment": {
"type": "object",
"description": "A binary attachment metadata",
"additionalProperties": false,
"properties": {
"filename": {
"description" : "Plain file name without any folders. Just a proposal to use when storing in file system.",
"type": "string"
},
"length": {
"description" : "The length of the binary content in bytes",
"type": "int"
},
"md5": {
"description" : "An md5 hash of the binary content",
"type": "string"
}
}
}
},

"type": "object",
"extends": {
"type": "object",
"javaType": "org.hawkular.bus.common.AbstractMessage"
},
"javaInterfaces" : ["org.hawkular.bus.common.BasicMessage", "org.hawkular.bus.common.msg.features.FailOnUnknownProperties"],
"javaType": "org.hawkular.cmdgw.api.AuthMessage",
"description": "Message properties that are needed for authentication.",
"additionalProperties": false,
"properties": {
"authentication": {
"$ref": "#/definitions/authentication"
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"type": "object",
"extends": {
"type": "object",
"javaType": "org.hawkular.cmdgw.api.AuthMessage"
},
"javaType": "org.hawkular.cmdgw.api.ResourcePathRequest",
"javaInterfaces" : ["org.hawkular.cmdgw.api.ResourcePathDestination", "org.hawkular.cmdgw.api.UiSessionOrigin"],
"description": "Adds a Datasource or a XA Datasource to a resource. The awkward name of the schema file A1ResourcePathRequest.schema.json 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": {
"resourcePath": {
"description" : "The inventory path to the Application Server resource where the driver should be installed",
"type": "string"
},
"senderRequestId": {
"description" : "An ID chosen by the sending UI client that should make it possible to associate future responses with this request. This ID is supposed to be unique just within the current WebSocket session.",
"type": "string"
},
"senderSessionId": {
"description" : "UI clients do not need to set this, the server will overwrite this field based on the ID of the present WebSocket session ID.",
"type": "string"
}
},
"required": ["resourcePath"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"type": "object",
"extends": {
"type": "object",
"javaType": "org.hawkular.cmdgw.api.AuthMessage"
},
"javaType": "org.hawkular.cmdgw.api.ResourcePathResponse",
"javaInterfaces" : ["org.hawkular.cmdgw.api.UiSessionDestination"],
"description": "Results of a Resource releated operation. The awkward name of the schema file A2ResourcePathResponse.schema.json 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": {
"resourcePath": {
"description" : "The inventory path to the resource that was targeted by the request.",
"type": "string"
},
"senderRequestId": {
"description" : "An ID chosen originally by the sending UI client that should make it possible to associate this response with the triggering request. This ID is supposed to be unique just within the sending WebSocket session",
"type": "string"
},
"destinationSessionId": {
"description" : "The ID of a WebSocket Session that is the destination of this message.",
"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 operation."
}
},
"required": ["resourcePath", "destinationSessionId"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@
"type": "object",
"extends": {
"type": "object",
"javaType": "org.hawkular.cmdgw.api.AuthMessage"
"javaType": "org.hawkular.cmdgw.api.ResourcePathRequest"
},
"javaType": "org.hawkular.cmdgw.api.AddDatasourceRequest",
"description": "Adds a Datasource or a XA Datasource to a resource.",
"additionalProperties": false,
"properties": {
"resourcePath": {
"description" : "The inventory path to the Application Server resource where the driver should be installed",
"type": "string"
},
"xaDatasource": {
"description" : "true if an XA datasource should be added, false otherwise",
"javaType": "boolean",
Expand Down Expand Up @@ -59,5 +55,5 @@
"type": "string"
}
},
"required": ["resourcePath", "isXaDatasource", "datasourceName", "jndiName", "driverName"]
"required": ["isXaDatasource", "datasourceName", "jndiName", "driverName"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,21 @@
"type": "object",
"extends": {
"type": "object",
"javaType": "org.hawkular.cmdgw.api.AuthMessage"
"javaType": "org.hawkular.cmdgw.api.ResourcePathResponse"
},
"javaType": "org.hawkular.cmdgw.api.AddDatasourceResponse",
"description": "Results of an Add Datasource request.",
"additionalProperties": false,
"properties": {
"resourcePath": {
"description" : "The inventory path to the Application Server resource that was targeted by the request.",
"type": "string"
},
"status": {
"type": "string",
"description": "Indicates if the deployment succeeded or failed."
"xaDatasource": {
"description" : "true if an XA datasource should be added, false otherwise",
"javaType": "boolean",
"type": "boolean"
},
"message": {
"type": "string",
"description": "A message that further describes the results of the operation."
"datasourceName": {
"description" : "The name for this datasource.",
"type": "string"
}
},
"required": ["resourcePath", "status"]
"required": ["xaDatasource", "datasourceName"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
"type": "object",
"extends": {
"type": "object",
"javaType": "org.hawkular.cmdgw.api.AuthMessage"
"javaType": "org.hawkular.cmdgw.api.ResourcePathRequest"
},
"javaType": "org.hawkular.cmdgw.api.AddJdbcDriverRequest",
"javaInterfaces" : ["org.hawkular.cmdgw.api.ResourcePathDestination"],
"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 Application Server resource where the driver should be installed",
"type": "string"
},
"driverName": {
"type": "string"
},
Expand All @@ -33,5 +30,5 @@
"type": "string"
}
},
"required": ["resourcePath", "driverName", "moduleName"]
"required": ["driverName", "moduleName"]
}
Loading

0 comments on commit 8c4ae14

Please sign in to comment.