aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openecomp/dmaapbc/resources
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/openecomp/dmaapbc/resources')
-rw-r--r--src/main/java/org/openecomp/dmaapbc/resources/ApiResource.java45
-rw-r--r--src/main/java/org/openecomp/dmaapbc/resources/BridgeResource.java111
-rw-r--r--src/main/java/org/openecomp/dmaapbc/resources/DR_NodeResource.java183
-rw-r--r--src/main/java/org/openecomp/dmaapbc/resources/DR_PubResource.java270
-rw-r--r--src/main/java/org/openecomp/dmaapbc/resources/DR_SubResource.java253
-rw-r--r--src/main/java/org/openecomp/dmaapbc/resources/DcaeLocationResource.java185
-rw-r--r--src/main/java/org/openecomp/dmaapbc/resources/DmaapResource.java140
-rw-r--r--src/main/java/org/openecomp/dmaapbc/resources/FeedResource.java227
-rw-r--r--src/main/java/org/openecomp/dmaapbc/resources/MR_ClientResource.java267
-rw-r--r--src/main/java/org/openecomp/dmaapbc/resources/MR_ClusterResource.java195
-rw-r--r--src/main/java/org/openecomp/dmaapbc/resources/RequiredFieldException.java30
-rw-r--r--src/main/java/org/openecomp/dmaapbc/resources/TopicResource.java184
12 files changed, 2090 insertions, 0 deletions
diff --git a/src/main/java/org/openecomp/dmaapbc/resources/ApiResource.java b/src/main/java/org/openecomp/dmaapbc/resources/ApiResource.java
new file mode 100644
index 0000000..a2a9e71
--- /dev/null
+++ b/src/main/java/org/openecomp/dmaapbc/resources/ApiResource.java
@@ -0,0 +1,45 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OpenECOMP - org.openecomp.dmaapbc
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.dmaapbc.resources;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.ws.rs.core.Response.Status;
+
+import org.openecomp.dmaapbc.model.ApiError;
+
+//TODO: Retire this class
+public class ApiResource {
+
+ static void checkRequired( String name, Object val, String expr, ApiError err ) throws RequiredFieldException {
+ if ( val == null ) {
+ err.setCode(Status.BAD_REQUEST.getStatusCode());
+ err.setMessage("missing required field");
+ err.setFields( name );
+ throw new RequiredFieldException();
+ }
+
+
+ }
+
+
+}
diff --git a/src/main/java/org/openecomp/dmaapbc/resources/BridgeResource.java b/src/main/java/org/openecomp/dmaapbc/resources/BridgeResource.java
new file mode 100644
index 0000000..0c5782a
--- /dev/null
+++ b/src/main/java/org/openecomp/dmaapbc/resources/BridgeResource.java
@@ -0,0 +1,111 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OpenECOMP - org.openecomp.dmaapbc
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.dmaapbc.resources;
+
+import java.util.List;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.log4j.Logger;
+import org.openecomp.dmaapbc.authentication.AuthenticationErrorException;
+import org.openecomp.dmaapbc.model.BrTopic;
+import org.openecomp.dmaapbc.model.MirrorMaker;
+import org.openecomp.dmaapbc.service.ApiService;
+import org.openecomp.dmaapbc.service.MirrorMakerService;
+
+@Path("/bridge")
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+public class BridgeResource {
+
+ static final Logger logger = Logger.getLogger(BridgeResource.class);
+
+ private MirrorMakerService mmService = new MirrorMakerService();
+
+ @GET
+ public Response getBridgedTopics(@QueryParam("source") String source,
+ @QueryParam("target") String target,
+ @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth){
+ ApiService check = new ApiService();
+ BrTopic brTopic = new BrTopic();
+
+ try {
+ check.checkAuthorization( basicAuth, uriInfo.getPath(), "GET");
+ } catch ( AuthenticationErrorException ae ) {
+ return check.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return check.unavailable();
+ }
+
+ logger.info( "getBridgeTopics():" + " source=" + source + ", target=" + target);
+// System.out.println("getBridgedTopics() " + "source=" + source + ", target=" + target );
+ if (source != null && target != null) { // get topics between 2 bridged locations
+ brTopic.setBrSource(source);
+ brTopic.setBrTarget(target);
+ MirrorMaker mm = mmService.getMirrorMaker(source, target);
+ if ( mm != null ) {
+ brTopic.setTopicCount( mm.getTopicCount() );
+ }
+
+ logger.info( "topicCount [2 locations]: " + brTopic.getTopicCount() );
+ }
+ else if (source == null && target == null ) {
+ List<String> mmList = mmService.getAllMirrorMakers();
+ brTopic.setBrSource("all");
+ brTopic.setBrTarget("all");
+ int totCnt = 0;
+ for( String key: mmList ) {
+ int mCnt = 0;
+ MirrorMaker mm = mmService.getMirrorMaker(key);
+ if ( mm != null ) {
+ mCnt = mm.getTopicCount();
+ }
+ logger.info( "Count for "+ key + ": " + mCnt);
+ totCnt += mCnt;
+ }
+
+ logger.info( "topicCount [all locations]: " + totCnt );
+ brTopic.setTopicCount(totCnt);
+// System.out.println("BridgeResource() d.getBrSource()=" + d.getBrSource());
+ }
+ else {
+// System.out.println("A source or target Parameter is missing");
+// return Response.serverError().build();
+ logger.error( "source or target is missing");
+ return Response.status(Status.BAD_REQUEST)
+ .entity( "Either 2 locations or no location must be provided")
+ .build();
+ }
+ return Response.ok(brTopic).
+ build();
+ }
+}
diff --git a/src/main/java/org/openecomp/dmaapbc/resources/DR_NodeResource.java b/src/main/java/org/openecomp/dmaapbc/resources/DR_NodeResource.java
new file mode 100644
index 0000000..73506f6
--- /dev/null
+++ b/src/main/java/org/openecomp/dmaapbc/resources/DR_NodeResource.java
@@ -0,0 +1,183 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OpenECOMP - org.openecomp.dmaapbc
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.dmaapbc.resources;
+
+import java.util.List;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.log4j.Logger;
+import org.openecomp.dmaapbc.authentication.AuthenticationErrorException;
+import org.openecomp.dmaapbc.model.DR_Node;
+import org.openecomp.dmaapbc.service.ApiService;
+import org.openecomp.dmaapbc.service.DR_NodeService;
+
+@Path("/dr_nodes")
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+public class DR_NodeResource extends ApiResource {
+ static final Logger logger = Logger.getLogger(DR_NodeResource.class);
+ DR_NodeService dr_nodeService = new DR_NodeService();
+
+ @GET
+ public List<DR_Node> getDr_Nodes(@Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth) {
+ ApiService resp = new ApiService();
+ try {
+ resp.checkAuthorization( basicAuth, uriInfo.getPath(), "GET");
+ } catch ( AuthenticationErrorException ae ) {
+ return null; //resp.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return null; //resp.unavailable();
+ }
+ return dr_nodeService.getAllDr_Nodes();
+ }
+
+ @POST
+ public Response addDr_Node( DR_Node node,
+ @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth) {
+ ApiService resp = new ApiService();
+ try {
+ resp.checkAuthorization( basicAuth, uriInfo.getPath(), "POST");
+ } catch ( AuthenticationErrorException ae ) {
+ return resp.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return resp.unavailable();
+ }
+ try {
+ resp.required( "dcaeLocation", node.getDcaeLocationName(), "");
+ resp.required( "fqdn", node.getFqdn(), "");
+ } catch ( RequiredFieldException rfe ) {
+ logger.debug( resp.toString() );
+ return Response.status(Status.BAD_REQUEST).entity( resp ).build();
+ }
+ DR_Node nNode = dr_nodeService.addDr_Node(node, resp.getErr());
+ if ( resp.getErr().is2xx()) {
+ return Response.status(Status.OK.getStatusCode())
+ .entity(nNode)
+ .build();
+ }
+ return Response.status( resp.getErr().getCode())
+ .entity( resp.getErr() )
+ .build();
+ }
+
+ @PUT
+ @Path("/{fqdn}")
+ public Response updateDr_Node( @PathParam("fqdn") String name, DR_Node node,
+ @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth) {
+ ApiService resp = new ApiService();
+ try {
+ resp.checkAuthorization( basicAuth, uriInfo.getPathSegments().get(0).getPath(), "PUT");
+ } catch ( AuthenticationErrorException ae ) {
+ return resp.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return resp.unavailable();
+ }
+ try {
+ resp.required( "dcaeLocation", name, "");
+ resp.required( "fqdn", node.getFqdn(), "");
+ } catch ( RequiredFieldException rfe ) {
+ logger.debug( resp.toString() );
+ return Response.status(Status.BAD_REQUEST).entity( resp ).build();
+ }
+ node.setFqdn(name);
+ DR_Node nNode = dr_nodeService.updateDr_Node(node, resp.getErr());
+ if ( resp.getErr().is2xx()) {
+ return Response.status(Status.OK.getStatusCode())
+ .entity(nNode)
+ .build();
+ }
+ return Response.status( resp.getErr().getCode())
+ .entity( resp.getErr() )
+ .build();
+ }
+
+ @DELETE
+ @Path("/{fqdn}")
+ public Response deleteDr_Node( @PathParam("fqdn") String name,
+ @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth){
+
+ ApiService resp = new ApiService();
+
+ try {
+ resp.checkAuthorization( basicAuth, uriInfo.getPathSegments().get(0).getPath(), "DELETE");
+ } catch ( AuthenticationErrorException ae ) {
+ return resp.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return resp.unavailable();
+ }
+ try {
+ resp.required( "fqdn", name, "");
+ } catch ( RequiredFieldException rfe ) {
+ logger.debug( resp.toString() );
+ return Response.status(Status.BAD_REQUEST).entity( resp ).build();
+ }
+ dr_nodeService.removeDr_Node(name, resp.getErr());
+ if ( resp.getErr().is2xx() ) {
+ return Response.status(Status.NO_CONTENT.getStatusCode())
+ .build();
+ }
+ return Response.status( resp.getErr().getCode())
+ .entity( resp.getErr() )
+ .build();
+ }
+
+ @GET
+ @Path("/{fqdn}")
+ public Response get( @PathParam("fqdn") String name,
+ @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth) {
+ ApiService resp = new ApiService();
+ try {
+ resp.checkAuthorization( basicAuth, uriInfo.getPathSegments().get(0).getPath(), "GET");
+ } catch ( AuthenticationErrorException ae ) {
+ return resp.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return resp.unavailable();
+ }
+ DR_Node nNode = dr_nodeService.getDr_Node( name, resp.getErr() );
+ if ( resp.getErr().is2xx() ) {
+ return Response.status(Status.OK.getStatusCode())
+ .entity(nNode)
+ .build();
+ }
+ return Response.status( resp.getErr().getCode())
+ .entity( resp.getErr() )
+ .build();
+ }
+}
diff --git a/src/main/java/org/openecomp/dmaapbc/resources/DR_PubResource.java b/src/main/java/org/openecomp/dmaapbc/resources/DR_PubResource.java
new file mode 100644
index 0000000..108a18b
--- /dev/null
+++ b/src/main/java/org/openecomp/dmaapbc/resources/DR_PubResource.java
@@ -0,0 +1,270 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OpenECOMP - org.openecomp.dmaapbc
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.dmaapbc.resources;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.log4j.Logger;
+import org.openecomp.dmaapbc.authentication.AuthenticationErrorException;
+import org.openecomp.dmaapbc.model.ApiError;
+import org.openecomp.dmaapbc.model.DR_Pub;
+import org.openecomp.dmaapbc.model.Feed;
+import org.openecomp.dmaapbc.service.ApiService;
+import org.openecomp.dmaapbc.service.DR_PubService;
+import org.openecomp.dmaapbc.service.FeedService;
+
+
+@Path("/dr_pubs")
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+public class DR_PubResource extends ApiResource {
+ static final Logger logger = Logger.getLogger(DR_PubResource.class);
+ DR_PubService dr_pubService = new DR_PubService();
+
+ @GET
+ public List<DR_Pub> getDr_Pubs(@Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth) {
+ ApiService resp = new ApiService();
+ try {
+ resp.checkAuthorization( basicAuth, uriInfo.getPath(), "GET");
+ } catch ( AuthenticationErrorException ae ) {
+ return null; //resp.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return null; //resp.unavailable();
+ }
+ logger.info( "Entry: GET /dr_pubs");
+ return dr_pubService.getAllDr_Pubs();
+ }
+
+ @POST
+ public Response addDr_Pub( DR_Pub pub,
+ @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth) {
+ ApiService resp = new ApiService();
+ try {
+ resp.checkAuthorization( basicAuth, uriInfo.getPath(), "POST");
+ } catch ( AuthenticationErrorException ae ) {
+ return resp.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return resp.unavailable();
+ }
+ logger.info( "Entry: POST /dr_pubs");
+ ApiError err = new ApiError();
+ try {
+ checkRequired( "feedId", pub.getFeedId(), "", err);
+ checkRequired( "dcaeLocationName", pub.getDcaeLocationName(), "", err);
+ } catch ( RequiredFieldException rfe ) {
+ logger.debug( err.toString() );
+ return Response.status(Status.BAD_REQUEST).entity( err ).build();
+ }
+
+ FeedService feeds = new FeedService();
+ Feed fnew = feeds.getFeed( pub.getFeedId(), err);
+ if ( fnew == null ) {
+ logger.info( "Specified feed " + pub.getFeedId() + " not known to Bus Controller");
+ return Response.status(err.getCode())
+ .entity( err )
+ .build();
+ }
+
+ ArrayList<DR_Pub> pubs = fnew.getPubs();
+ logger.info( "num existing pubs before = " + pubs.size() );
+/*
+ DR_Pub pnew = new DR_Pub( pub.getDcaeLocationName());
+ pnew.setFeedId(pub.getFeedId());
+ pnew.setPubId(pub.getPubId());
+ String tmp = pub.getUsername();
+ if ( tmp != null ) {
+ pub.setUsername(tmp);
+ }
+ tmp = pub.getUserpwd();
+ if ( tmp != null ) {
+ pub.setUserpwd(tmp);
+ }
+ pnew.setNextPubId();
+*/
+
+
+ logger.info( "update feed");
+ pub.setNextPubId();
+ if ( pub.getUsername() == null ) {
+ pub.setRandomUserName();
+ }
+ if ( pub.getUserpwd() == null ) {
+ pub.setRandomPassword();
+ }
+ pubs.add( pub );
+ fnew.setPubs(pubs);
+ fnew = feeds.updateFeed( fnew, err );
+
+ if ( ! err.is2xx()) {
+ return Response.status(err.getCode())
+ .entity( err )
+ .build();
+ }
+ pubs = fnew.getPubs();
+ logger.info( "num existing pubs after = " + pubs.size() );
+
+ DR_Pub pnew = dr_pubService.getDr_Pub(pub.getPubId(), err);
+ return Response.status(Status.CREATED.getStatusCode())
+ .entity(pnew)
+ .build();
+ }
+
+ @PUT
+ @Path("/{pubId}")
+ public Response updateDr_Pub( @PathParam("pubId") String name, DR_Pub pub,
+ @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth) {
+ ApiService resp = new ApiService();
+ try {
+ resp.checkAuthorization( basicAuth, uriInfo.getPathSegments().get(0).getPath(), "PUT");
+ } catch ( AuthenticationErrorException ae ) {
+ return resp.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return resp.unavailable();
+ }
+ logger.info( "Entry: PUT /dr_pubs");
+ pub.setPubId(name);
+ DR_Pub res = dr_pubService.updateDr_Pub(pub);
+ return Response.ok()
+ .entity(res)
+ .build();
+ }
+
+ @DELETE
+ @Path("/{pubId}")
+ public Response deleteDr_Pub( @PathParam("pubId") String id,
+ @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth){
+ logger.info( "Entry: DELETE /dr_pubs");
+ ApiService resp = new ApiService();
+ try {
+ resp.checkAuthorization( basicAuth, uriInfo.getPathSegments().get(0).getPath(), "DELETE");
+ } catch ( AuthenticationErrorException ae ) {
+ return resp.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return resp.unavailable();
+ }
+ ApiError err = new ApiError();
+ try {
+ checkRequired( "feedId", id, "", err);
+ } catch ( RequiredFieldException rfe ) {
+ logger.debug( err.toString() );
+ return Response.status(Status.BAD_REQUEST).entity( err ).build();
+ }
+
+ DR_Pub pub = dr_pubService.getDr_Pub( id, err );
+ if ( ! err.is2xx()) {
+ return Response.status(err.getCode())
+ .entity( err )
+ .build();
+ }
+ FeedService feeds = new FeedService();
+ Feed fnew = feeds.getFeed( pub.getFeedId(), err);
+ if ( fnew == null ) {
+ logger.info( "Specified feed " + pub.getFeedId() + " not known to Bus Controller");
+ return Response.status(err.getCode())
+ .entity( err )
+ .build();
+ }
+ ArrayList<DR_Pub> pubs = fnew.getPubs();
+ if ( pubs.size() == 1 ) {
+ err.setCode(Status.BAD_REQUEST.getStatusCode());
+ err.setMessage( "Can't delete the last publisher of a feed");
+ return Response.status(err.getCode())
+ .entity( err )
+ .build();
+ }
+ Iterator<DR_Pub> i = pubs.iterator();
+ while( i.hasNext() ) {
+ DR_Pub listItem = i.next();
+ if ( listItem.getPubId().equals(id)) {
+ pubs.remove( listItem );
+ }
+ }
+ fnew.setPubs(pubs);
+ fnew = feeds.updateFeed( fnew, err );
+ if ( ! err.is2xx()) {
+ return Response.status(err.getCode())
+ .entity( err )
+ .build();
+ }
+
+ dr_pubService.removeDr_Pub(id, err);
+ if ( ! err.is2xx()) {
+ return Response.status(err.getCode())
+ .entity( err )
+ .build();
+ }
+ return Response.status(Status.NO_CONTENT.getStatusCode())
+ .build();
+ }
+
+ @GET
+ @Path("/{pubId}")
+ public Response get( @PathParam("pubId") String id,
+ @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth) {
+ ApiService resp = new ApiService();
+ try {
+ resp.checkAuthorization( basicAuth, uriInfo.getPathSegments().get(0).getPath(), "GET");
+ } catch ( AuthenticationErrorException ae ) {
+ return resp.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return resp.unavailable();
+ }
+ ApiError err = new ApiError();
+ try {
+ checkRequired( "feedId", id, "", err);
+ } catch ( RequiredFieldException rfe ) {
+ logger.debug( err.toString() );
+ return Response.status(Status.BAD_REQUEST).entity( err ).build();
+ }
+ logger.info( "Entry: GET /dr_pubs");
+ DR_Pub pub = dr_pubService.getDr_Pub( id, err );
+ if ( ! err.is2xx()) {
+ return Response.status(err.getCode())
+ .entity( err )
+ .build();
+ }
+ return Response.status(Status.OK.getStatusCode())
+ .entity(pub)
+ .build();
+ }
+}
diff --git a/src/main/java/org/openecomp/dmaapbc/resources/DR_SubResource.java b/src/main/java/org/openecomp/dmaapbc/resources/DR_SubResource.java
new file mode 100644
index 0000000..e0b42ce
--- /dev/null
+++ b/src/main/java/org/openecomp/dmaapbc/resources/DR_SubResource.java
@@ -0,0 +1,253 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OpenECOMP - org.openecomp.dmaapbc
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.dmaapbc.resources;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.core.Response.Status;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+import org.apache.log4j.Logger;
+import org.openecomp.dmaapbc.authentication.AuthenticationErrorException;
+import org.openecomp.dmaapbc.model.DR_Sub;
+import org.openecomp.dmaapbc.model.Feed;
+import org.openecomp.dmaapbc.service.ApiService;
+import org.openecomp.dmaapbc.service.DR_SubService;
+import org.openecomp.dmaapbc.service.FeedService;
+
+
+@Path("/dr_subs")
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+public class DR_SubResource extends ApiResource {
+ static final Logger logger = Logger.getLogger(DR_SubResource.class);
+
+
+ @GET
+ public List<DR_Sub> getDr_Subs(@Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth) {
+ logger.info( "Entry: GET /dr_subs");
+ ApiService resp = new ApiService();
+ try {
+ resp.checkAuthorization( basicAuth, uriInfo.getPath(), "GET");
+ } catch ( AuthenticationErrorException ae ) {
+ return null; //resp.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return null; //resp.unavailable();
+ }
+ DR_SubService dr_subService = new DR_SubService();
+ return dr_subService.getAllDr_Subs();
+ }
+
+ @POST
+ public Response addDr_Sub( DR_Sub sub,
+ @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth) {
+ logger.info( "Entry: POST /dr_subs");
+ ApiService resp = new ApiService();
+ try {
+ resp.checkAuthorization( basicAuth, uriInfo.getPath(), "POST");
+ } catch ( AuthenticationErrorException ae ) {
+ return resp.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return resp.unavailable();
+ }
+
+ try {
+ resp.required( "feedId", sub.getFeedId(), "");
+ resp.required( "dcaeLocationName", sub.getDcaeLocationName(), "");
+
+ } catch ( RequiredFieldException rfe ) {
+ logger.debug( resp.toString() );
+ return Response.status(Status.BAD_REQUEST)
+ .entity( resp.getErr() )
+ .build();
+ }
+
+ FeedService feeds = new FeedService();
+ Feed fnew = feeds.getFeed( sub.getFeedId(), resp.getErr() );
+ if ( fnew == null ) {
+ logger.warn( "Specified feed " + sub.getFeedId() + " not known to Bus Controller");
+ return Response.status( resp.getErr().getCode() )
+ .entity( resp.getErr() )
+ .build();
+ }
+
+ DR_SubService dr_subService = new DR_SubService( fnew.getSubscribeURL());
+ ArrayList<DR_Sub> subs = fnew.getSubs();
+ logger.info( "num existing subs before = " + subs.size() );
+ DR_Sub snew = dr_subService.addDr_Sub(sub, resp.getErr() );
+ if ( ! resp.getErr().is2xx() ) {
+ return Response.status( resp.getErr().getCode() )
+ .entity( resp.getErr() )
+ .build();
+ }
+ subs.add( snew );
+ logger.info( "num existing subs after = " + subs.size() );
+
+ fnew.setSubs(subs);
+ logger.info( "update feed");
+ //feeds.updateFeed( fnew, err );
+
+ return Response.status(Status.CREATED)
+ .entity(snew)
+ .build();
+
+ }
+
+ @PUT
+ @Path("/{subId}")
+ public Response updateDr_Sub( @PathParam("subId") String name, DR_Sub sub,
+ @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth) {
+ logger.info( "Entry: PUT /dr_subs");
+ ApiService resp = new ApiService();
+ try {
+ resp.checkAuthorization( basicAuth, uriInfo.getPathSegments().get(0).getPath(), "PUT");
+ } catch ( AuthenticationErrorException ae ) {
+ return resp.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return resp.unavailable();
+ }
+
+ try {
+ resp.required( "subId", name, "");
+ resp.required( "feedId", sub.getFeedId(), "");
+ resp.required( "dcaeLocationName", sub.getDcaeLocationName(), "");
+
+ } catch ( RequiredFieldException rfe ) {
+ logger.debug( resp.toString() );
+ return Response.status(Status.BAD_REQUEST)
+ .entity( resp.getErr() )
+ .build();
+ }
+ DR_SubService dr_subService = new DR_SubService();
+ sub.setSubId(name);
+ DR_Sub nsub = dr_subService.updateDr_Sub(sub, resp.getErr() );
+ if ( nsub != null && nsub.isStatusValid() ) {
+ return Response.status(Status.OK)
+ .entity(nsub)
+ .build();
+ }
+ return Response.status(resp.getErr().getCode())
+ .entity(resp.getErr())
+ .build();
+ }
+
+ @DELETE
+ @Path("/{subId}")
+ public Response deleteDr_Sub( @PathParam("subId") String id,
+ @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth){
+ logger.info( "Entry: DELETE /dr_subs");
+ ApiService resp = new ApiService();
+ try {
+ resp.checkAuthorization( basicAuth, uriInfo.getPathSegments().get(0).getPath(), "DELETE");
+ } catch ( AuthenticationErrorException ae ) {
+ return resp.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return resp.unavailable();
+ }
+
+ try {
+ resp.required( "subId", id, "");
+ } catch ( RequiredFieldException rfe ) {
+ logger.debug( resp.toString() );
+ return Response.status(Status.BAD_REQUEST.getStatusCode())
+ .entity( resp.getErr() )
+ .build();
+ }
+ DR_SubService dr_subService = new DR_SubService();
+ dr_subService.removeDr_Sub(id, resp.getErr() );
+ if ( ! resp.getErr().is2xx() ) {
+ return Response.status( resp.getErr().getCode() )
+ .entity( resp.getErr() )
+ .build();
+ }
+ return Response.status(Status.NO_CONTENT.getStatusCode())
+ .build();
+ }
+
+ @GET
+ @Path("/{subId}")
+ public Response get( @PathParam("subId") String id,
+ @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth) {
+ logger.info( "Entry: GET /dr_subs");
+ ApiService resp = new ApiService();
+ try {
+ resp.checkAuthorization( basicAuth, uriInfo.getPathSegments().get(0).getPath(), "GET");
+ } catch ( AuthenticationErrorException ae ) {
+ return resp.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return resp.unavailable();
+ }
+
+ try {
+ resp.required( "subId", id, "");
+ } catch ( RequiredFieldException rfe ) {
+ logger.debug( resp.toString() );
+ return Response.status(Status.BAD_REQUEST.getStatusCode())
+ .entity( resp.getErr() )
+ .build();
+ }
+ DR_SubService dr_subService = new DR_SubService();
+ DR_Sub sub = dr_subService.getDr_Sub( id, resp.getErr() );
+ if ( sub != null && sub.isStatusValid() ) {
+ return Response.status(Status.OK.getStatusCode())
+ .entity(sub)
+ .build();
+ }
+ return Response.status(resp.getErr().getCode())
+ .entity(resp.getErr())
+ .build();
+ }
+}
diff --git a/src/main/java/org/openecomp/dmaapbc/resources/DcaeLocationResource.java b/src/main/java/org/openecomp/dmaapbc/resources/DcaeLocationResource.java
new file mode 100644
index 0000000..9d158fa
--- /dev/null
+++ b/src/main/java/org/openecomp/dmaapbc/resources/DcaeLocationResource.java
@@ -0,0 +1,185 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OpenECOMP - org.openecomp.dmaapbc
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.dmaapbc.resources;
+
+
+import java.util.List;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.PathSegment;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.log4j.Logger;
+
+
+
+import org.openecomp.dmaapbc.authentication.AuthenticationErrorException;
+import org.openecomp.dmaapbc.model.ApiError;
+import org.openecomp.dmaapbc.model.DcaeLocation;
+import org.openecomp.dmaapbc.service.ApiService;
+import org.openecomp.dmaapbc.service.DcaeLocationService;
+
+
+@Path("/dcaeLocations")
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+public class DcaeLocationResource {
+ static final Logger logger = Logger.getLogger(DcaeLocationResource.class);
+ DcaeLocationService locationService = new DcaeLocationService();
+
+ @GET
+ public List<DcaeLocation> getDcaeLocations( @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth) {
+ ApiService check = new ApiService();
+ try {
+ check.checkAuthorization( basicAuth, uriInfo.getPath(), "GET");
+ } catch ( AuthenticationErrorException ae ) {
+ return null; //check.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return null; //check.unavailable();
+ }
+ return locationService.getAllDcaeLocations();
+ }
+
+ @POST
+ public Response addDcaeLocation( DcaeLocation location,
+ @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth ) {
+ ApiService check = new ApiService();
+ try {
+ check.checkAuthorization( basicAuth, uriInfo.getPath(), "POST");
+ } catch ( AuthenticationErrorException ae ) {
+ return check.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return check.unavailable();
+ }
+ if ( locationService.getDcaeLocation(location.getDcaeLocationName()) != null ) {
+ ApiError err = new ApiError();
+
+ err.setCode(Status.CONFLICT.getStatusCode());
+ err.setMessage("dcaeLocation already exists");
+ err.setFields("dcaeLocation");
+
+ logger.warn( err );
+ return Response.status(Status.CONFLICT).entity( err ).build();
+
+
+ }
+ DcaeLocation loc = locationService.addDcaeLocation(location);
+ return Response.status(Status.CREATED)
+ .entity(loc)
+ .build();
+ }
+
+ @PUT
+ @Path("/{locationName}")
+ public Response updateDcaeLocation( @PathParam("locationName") String name, DcaeLocation location,
+ @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth) {
+ ApiService check = new ApiService();
+ try {
+ check.checkAuthorization( basicAuth, uriInfo.getPathSegments().get(0).getPath(), "PUT");
+ } catch ( AuthenticationErrorException ae ) {
+ return check.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return check.unavailable();
+ }
+ location.setDcaeLocationName(name);
+ if ( locationService.getDcaeLocation(location.getDcaeLocationName()) == null ) {
+ ApiError err = new ApiError();
+
+ err.setCode(Status.NOT_FOUND.getStatusCode());
+ err.setMessage("dcaeLocation does not exist");
+ err.setFields("dcaeLocation");
+
+ logger.warn( err );
+ return Response.status(Status.NOT_FOUND).entity( err ).build();
+
+
+ }
+ DcaeLocation loc = locationService.updateDcaeLocation(location);
+ return Response.status(Status.CREATED)
+ .entity(loc)
+ .build();
+ }
+
+ @DELETE
+ @Path("/{locationName}")
+ public Response deleteDcaeLocation( @PathParam("locationName") String name,
+ @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth){
+ ApiService check = new ApiService();
+ try {
+ check.checkAuthorization( basicAuth, uriInfo.getPathSegments().get(0).getPath(), "DELETE");
+ } catch ( AuthenticationErrorException ae ) {
+ return check.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return check.unavailable();
+ }
+ locationService.removeDcaeLocation(name);
+ return Response.status(Status.NO_CONTENT).build();
+ }
+
+ @GET
+ @Path("/{locationName}")
+ public Response getDcaeLocation( @PathParam("locationName") String name,
+ @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth) {
+ ApiService check = new ApiService();
+ try {
+ //List<PathSegment> segments = uriInfo.getPathSegments();
+ check.checkAuthorization( basicAuth, uriInfo.getPathSegments().get(0).getPath(), "GET");
+ } catch ( AuthenticationErrorException ae ) {
+ return check.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return check.unavailable();
+ }
+ DcaeLocation loc = locationService.getDcaeLocation( name );
+ if ( loc == null ) {
+ ApiError err = new ApiError();
+
+ err.setCode(Status.NOT_FOUND.getStatusCode());
+ err.setMessage("dcaeLocation does not exist");
+ err.setFields("dcaeLocation");
+
+ logger.warn( err );
+ return Response.status(Status.NOT_FOUND).entity( err ).build();
+
+
+ }
+
+ return Response.status(Status.OK)
+ .entity(loc)
+ .build();
+ }
+}
diff --git a/src/main/java/org/openecomp/dmaapbc/resources/DmaapResource.java b/src/main/java/org/openecomp/dmaapbc/resources/DmaapResource.java
new file mode 100644
index 0000000..03c731f
--- /dev/null
+++ b/src/main/java/org/openecomp/dmaapbc/resources/DmaapResource.java
@@ -0,0 +1,140 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OpenECOMP - org.openecomp.dmaapbc
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+//
+// $Id$
+
+package org.openecomp.dmaapbc.resources;
+
+
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.log4j.Logger;
+import org.openecomp.dmaapbc.authentication.AuthenticationErrorException;
+import org.openecomp.dmaapbc.model.Dmaap;
+import org.openecomp.dmaapbc.service.ApiService;
+import org.openecomp.dmaapbc.service.DmaapService;
+
+
+
+@Path("/dmaap")
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+public class DmaapResource {
+ static final Logger logger = Logger.getLogger(DmaapResource.class);
+
+ DmaapService dmaapService = new DmaapService();
+
+ @GET
+ public Response getDmaap(@Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth ) {
+ logger.debug( "Entry: GET " + uriInfo.getPath() );
+ ApiService check = new ApiService();
+ try {
+ check.checkAuthorization( basicAuth, uriInfo.getPath(), "GET");
+ } catch ( AuthenticationErrorException ae ) {
+ return check.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return check.unavailable();
+ }
+ Dmaap d = dmaapService.getDmaap();
+ return Response.ok(d)
+ .build();
+ }
+
+ @POST
+ public Response addDmaap( Dmaap obj,@Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth ) {
+
+ ApiService check = new ApiService();
+ try {
+ check.checkAuthorization( basicAuth, uriInfo.getPath(), "POST");
+ } catch ( AuthenticationErrorException ae ) {
+ return check.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return check.unavailable();
+ }
+ try { //check for required fields
+ check.required( "dmaapName", obj.getDmaapName(), "^\\S+$" ); //no white space allowed in dmaapName
+ check.required( "dmaapProvUrl", obj.getDrProvUrl(), "" );
+ check.required( "topicNsRoot", obj.getTopicNsRoot(), "" );
+ check.required( "bridgeAdminTopic", obj.getBridgeAdminTopic(), "" );
+ } catch( RequiredFieldException rfe ) {
+ return Response.status(check.getErr().getCode())
+ .entity( check.getErr() )
+ .build();
+ }
+
+ Dmaap d = dmaapService.addDmaap(obj);
+ if ( d == null ) {
+ return Response.status(Status.NOT_FOUND)
+ .build();
+
+ }
+
+ return Response.ok(d)
+ .build();
+ }
+
+ @PUT
+ public Response updateDmaap( Dmaap obj, @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth ) {
+ ApiService check = new ApiService();
+ try {
+ check.checkAuthorization( basicAuth, uriInfo.getPath(), "PUT");
+ } catch ( AuthenticationErrorException ae ) {
+ return check.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return check.unavailable();
+ }
+ try { //check for required fields
+ check.required( "dmaapName", obj.getDmaapName(), "^\\S+$" ); //no white space allowed in dmaapName
+ check.required( "dmaapProvUrl", obj.getDrProvUrl(), "" );
+ check.required( "topicNsRoot", obj.getTopicNsRoot(), "" );
+ check.required( "bridgeAdminTopic", obj.getBridgeAdminTopic(), "" );
+ } catch( RequiredFieldException rfe ) {
+ return Response.status(check.getErr().getCode())
+ .entity( check.getErr() )
+ .build();
+ }
+ Dmaap d = dmaapService.updateDmaap(obj);
+ if ( d != null ) {
+ return Response.ok(d)
+ .build();
+ } else {
+ return Response.status(Status.NOT_FOUND)
+ .build();
+ }
+ }
+
+
+}
diff --git a/src/main/java/org/openecomp/dmaapbc/resources/FeedResource.java b/src/main/java/org/openecomp/dmaapbc/resources/FeedResource.java
new file mode 100644
index 0000000..b1dcd57
--- /dev/null
+++ b/src/main/java/org/openecomp/dmaapbc/resources/FeedResource.java
@@ -0,0 +1,227 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OpenECOMP - org.openecomp.dmaapbc
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.dmaapbc.resources;
+
+import java.util.List;
+
+import javax.jws.WebParam;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.log4j.Logger;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+import org.openecomp.dmaapbc.authentication.AuthenticationErrorException;
+import org.openecomp.dmaapbc.model.Feed;
+import org.openecomp.dmaapbc.service.ApiService;
+import org.openecomp.dmaapbc.service.FeedService;
+
+
+@Path("/feeds")
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+public class FeedResource extends ApiResource {
+ static final Logger logger = Logger.getLogger(FeedResource.class);
+
+
+ @GET
+ public List<Feed> getFeeds(@Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth) {
+ logger.debug( "Entry: GET " + uriInfo.getPath() );
+ ApiService resp = new ApiService();
+ try {
+ resp.checkAuthorization( basicAuth, uriInfo.getPath(), "GET");
+ } catch ( AuthenticationErrorException ae ) {
+ return null; //resp.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return null; //resp.unavailable();
+ }
+ FeedService feedService = new FeedService();
+ List<Feed> nfeeds = feedService.getAllFeeds();
+// tried this: http://www.adam-bien.com/roller/abien/entry/jax_rs_returning_a_list
+// but still didn't seem to work...
+// GenericEntity<List<Feed>> list = new GenericEntity<List<Feed>>(nfeeds){};
+// return Response.status(Status.OK)
+// .entity( list )
+// .build();
+ return nfeeds;
+ }
+
+
+
+ @POST
+ public Response addFeed( @WebParam(name = "feed") Feed feed , @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth ) {
+ logger.debug( "Entry: POST " + uriInfo.getPath());
+
+ ApiService resp = new ApiService();
+ try {
+ resp.checkAuthorization( basicAuth, uriInfo.getPath(), "POST");
+ } catch ( AuthenticationErrorException ae ) {
+ return resp.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return resp.unavailable();
+ }
+ try {
+ resp.required( "feedName", feed.getFeedName(), "");
+ resp.required( "feedVersion", feed.getFeedVersion(), "");
+ resp.required( "owner", feed.getOwner(), "" );
+ resp.required( "asprClassification", feed.getAsprClassification(), "" );
+ } catch ( RequiredFieldException rfe ) {
+ logger.debug( resp.toString() );
+ return Response.status(Status.BAD_REQUEST).entity( resp ).build();
+ }
+
+ FeedService feedService = new FeedService();
+ Feed nfeed = feedService.addFeed( feed, resp.getErr() );
+ if ( nfeed != null ) {
+ return Response.status(Status.OK)
+ .entity(nfeed)
+ .build();
+ } else {
+ logger.error( "Unable to create: " + feed.getFeedName() + ":" + feed.getFeedVersion());
+
+ return Response.status(resp.getErr().getCode())
+ .entity( resp )
+ .build();
+ }
+ }
+
+ @PUT
+ @Path("/{id}")
+ public Response updateFeed( @PathParam("id") String id, Feed feed, @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth) {
+ logger.debug( "Entry: PUT " + uriInfo.getPath());
+
+ FeedService feedService = new FeedService();
+ ApiService resp = new ApiService();
+ try {
+ resp.checkAuthorization( basicAuth, uriInfo.getPathSegments().get(0).getPath(), "PUT");
+ } catch ( AuthenticationErrorException ae ) {
+ return resp.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return resp.unavailable();
+ }
+ try {
+ resp.required( "feedId", id, "");
+ } catch ( RequiredFieldException rfe ) {
+ logger.debug( resp.toString() );
+ return Response.status(Status.BAD_REQUEST.getStatusCode()).entity( resp ).build();
+ }
+
+ Feed nfeed = feedService.getFeed( id, resp.getErr() );
+ if ( nfeed == null ) {
+ return Response.status(resp.getErr().getCode())
+ .entity( resp.getErr() )
+ .build();
+ }
+
+ // we assume there is no updates allowed for pubs and subs objects via this api...
+ // need to update any fields supported by PUT but preserve original field values.
+ nfeed.setSuspended(feed.isSuspended());
+ nfeed.setFeedDescription(feed.getFeedDescription());
+ nfeed.setFormatUuid(feed.getFormatUuid());
+
+ nfeed = feedService.updateFeed(nfeed, resp.getErr());
+ if ( nfeed != null ) {
+ return Response.status(Status.OK)
+ .entity(nfeed)
+ .build();
+ } else {
+ logger.info( "Unable to update: " + feed.getFeedName() + ":" + feed.getFeedVersion());
+
+ return Response.status(resp.getErr().getCode())
+ .entity( resp.getErr() )
+ .build();
+ }
+ }
+
+ @DELETE
+ @Path("/{id}")
+ public Response deleteFeed( @PathParam("id") String id, @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth ){
+ ApiService resp = new ApiService();
+ try {
+ resp.checkAuthorization( basicAuth, uriInfo.getPathSegments().get(0).getPath(), "DELETE");
+ } catch ( AuthenticationErrorException ae ) {
+ return resp.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return resp.unavailable();
+ }
+ logger.debug( "Entry: DELETE " + uriInfo.getPath());
+ FeedService feedService = new FeedService();
+ feedService.removeFeed(id);
+ return Response.status(Status.NO_CONTENT)
+ .build();
+ }
+
+ @GET
+ @Path("/{id}")
+ public Response getFeed( @PathParam("id") String id, @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth ) {
+ logger.debug( "Entry: GET " + uriInfo.getPath());
+ ApiService resp = new ApiService();
+ try {
+ resp.checkAuthorization( basicAuth, uriInfo.getPathSegments().get(0).getPath(), "GET");
+ } catch ( AuthenticationErrorException ae ) {
+ return resp.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return resp.unavailable();
+ }
+ FeedService feedService = new FeedService();
+ Feed nfeed = feedService.getFeed( id, resp.getErr() );
+ if ( nfeed == null ) {
+ return Response.status(Status.NOT_FOUND).entity( resp.getErr() ).build();
+ }
+ return Response.status(Status.OK)
+ .entity(nfeed)
+ .build();
+ }
+}
diff --git a/src/main/java/org/openecomp/dmaapbc/resources/MR_ClientResource.java b/src/main/java/org/openecomp/dmaapbc/resources/MR_ClientResource.java
new file mode 100644
index 0000000..7acc0a4
--- /dev/null
+++ b/src/main/java/org/openecomp/dmaapbc/resources/MR_ClientResource.java
@@ -0,0 +1,267 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OpenECOMP - org.openecomp.dmaapbc
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.dmaapbc.resources;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.log4j.Logger;
+import org.openecomp.dmaapbc.authentication.AuthenticationErrorException;
+import org.openecomp.dmaapbc.model.ApiError;
+import org.openecomp.dmaapbc.model.MR_Client;
+import org.openecomp.dmaapbc.model.MR_Cluster;
+import org.openecomp.dmaapbc.model.Topic;
+import org.openecomp.dmaapbc.service.ApiService;
+import org.openecomp.dmaapbc.service.MR_ClientService;
+import org.openecomp.dmaapbc.service.MR_ClusterService;
+import org.openecomp.dmaapbc.service.TopicService;
+
+
+@Path("/mr_clients")
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+public class MR_ClientResource extends ApiResource {
+ static final Logger logger = Logger.getLogger(MR_ClientResource.class);
+ private MR_ClientService mr_clientService = new MR_ClientService();
+
+ @GET
+ public List<MR_Client> getMr_Clients(@Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth) {
+ ApiService resp = new ApiService();
+ try {
+ resp.checkAuthorization( basicAuth, uriInfo.getPath(), "GET");
+ } catch ( AuthenticationErrorException ae ) {
+ return null; //resp.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return null; //resp.unavailable();
+ }
+ return mr_clientService.getAllMr_Clients();
+ }
+
+ @POST
+ public Response addMr_Client( MR_Client client,
+ @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth) {
+ ApiService resp = new ApiService();
+ try {
+ resp.checkAuthorization( basicAuth, uriInfo.getPath(), "POST");
+ } catch ( AuthenticationErrorException ae ) {
+ return resp.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return resp.unavailable();
+ }
+ try {
+ resp.required( "fqtn", client.getFqtn(), "");
+ resp.required( "dcaeLocationName", client.getDcaeLocationName(), "");
+ resp.required( "clientRole", client.getClientRole(), "" );
+ resp.required( "action", client.getAction(), "");
+
+ } catch ( RequiredFieldException rfe ) {
+ logger.debug( resp.toString() );
+ return Response.status(resp.getErr().getCode())
+ .entity( resp.getErr() )
+ .build();
+ }
+ MR_ClusterService clusters = new MR_ClusterService();
+
+ MR_Cluster cluster = clusters.getMr_Cluster(client.getDcaeLocationName(), resp.getErr());
+ if ( cluster == null ) {
+ ApiError err = resp.getErr();
+ err.setCode(Status.BAD_REQUEST.getStatusCode());
+ err.setMessage( "MR_Cluster alias not found for dcaeLocation: " + client.getDcaeLocationName());
+ err.setFields("dcaeLocationName");
+ logger.warn( err.getMessage() );
+ return Response.status(err.getCode()).entity( err ).build();
+ }
+ String url = cluster.getFqdn();
+ if ( url == null || url.isEmpty() ) {
+ ApiError err = resp.getErr();
+ err.setCode(Status.BAD_REQUEST.getStatusCode());
+ err.setMessage("FQDN not set for dcaeLocation " + client.getDcaeLocationName() );
+ err.setFields("fqdn");
+ logger.warn( err.getMessage() );
+ return Response.status(err.getCode()).entity( err ).build();
+ }
+ TopicService topics = new TopicService();
+ ApiError err = resp.getErr();
+ Topic t = topics.getTopic(client.getFqtn(), err);
+ if ( t == null ) {
+ return Response.status(err.getCode()).entity( err ).build();
+ }
+ MR_Client nClient = mr_clientService.addMr_Client(client, t, err);
+ if ( err.is2xx()) {
+ int n;
+ ArrayList<MR_Client> tc = t.getClients();
+ if ( tc == null ) {
+ n = 0;
+ tc = new ArrayList<MR_Client>();
+ } else {
+ n = tc.size();
+ }
+ logger.info( "number of existing clients for topic is " + n );
+
+
+ logger.info( "n=" + n + " tc=" + tc + " client=" + client );
+ tc.add( client );
+ t.setClients(tc);
+ topics.updateTopic( t );
+ return Response.ok(nClient)
+ .build();
+ }
+ else {
+ return Response.status(resp.getErr().getCode())
+ .entity( resp.getErr() )
+ .build();
+ }
+ }
+
+ @PUT
+ @Path("/{clientId}")
+ public Response updateMr_Client( @PathParam("clientId") String clientId, MR_Client client,
+ @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth) {
+ ApiService resp = new ApiService();
+ try {
+ resp.checkAuthorization( basicAuth, uriInfo.getPathSegments().get(0).getPath(), "PUT");
+ } catch ( AuthenticationErrorException ae ) {
+ return resp.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return resp.unavailable();
+ }
+ try {
+ resp.required( "fqtn", client.getFqtn(), "");
+ resp.required( "dcaeLocationName", client.getDcaeLocationName(), "");
+ resp.required( "clientRole", client.getClientRole(), "" );
+ resp.required( "action", client.getAction(), "");
+
+ } catch ( RequiredFieldException rfe ) {
+ logger.debug( resp.toString() );
+ return Response.status(resp.getErr().getCode())
+ .entity( resp.getErr() )
+ .build();
+ }
+ client.setMrClientId(clientId);
+ MR_Client nClient = mr_clientService.updateMr_Client(client, resp.getErr() );
+ if ( resp.getErr().is2xx()) {
+ return Response.ok(nClient)
+ .build();
+ }
+ return Response.status(resp.getErr().getCode())
+ .entity( resp.getErr() )
+ .build();
+ }
+
+ @DELETE
+ @Path("/{subId}")
+ public Response deleteMr_Client( @PathParam("subId") String id,
+ @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth){
+ ApiService resp = new ApiService();
+ try {
+ resp.checkAuthorization( basicAuth, uriInfo.getPathSegments().get(0).getPath(), "DELETE");
+ } catch ( AuthenticationErrorException ae ) {
+ return resp.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return resp.unavailable();
+ }
+ try {
+ resp.required( "clientId", id, "");
+ } catch ( RequiredFieldException rfe ) {
+ logger.debug( resp.toString() );
+ return Response.status(resp.getErr().getCode())
+ .entity( resp.getErr() )
+ .build();
+ }
+ MR_Client client = mr_clientService.removeMr_Client(id, resp.getErr() );
+ if ( resp.getErr().is2xx()) {
+ TopicService topics = new TopicService();
+ ApiError err = resp.getErr();
+ Topic t = topics.getTopic(client.getFqtn(), err);
+ if ( t == null ) {
+ logger.info( err.getMessage() );
+ return Response.status(err.getCode()).entity( err ).build();
+ }
+
+ ArrayList<MR_Client> tc = t.getClients();
+ for( MR_Client c: tc) {
+ if ( c.getMrClientId().equals(id)) {
+ tc.remove(c);
+ break;
+ }
+ }
+ t.setClients(tc);
+ topics.updateTopic( t );
+
+ return Response.status(Status.NO_CONTENT.getStatusCode())
+ .build();
+ }
+
+ return Response.status(resp.getErr().getCode())
+ .entity( resp.getErr() )
+ .build();
+ }
+
+ @GET
+ @Path("/{subId}")
+ public Response test( @PathParam("subId") String id,
+ @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth) {
+ ApiService resp = new ApiService();
+ try {
+ resp.checkAuthorization( basicAuth, uriInfo.getPathSegments().get(0).getPath(), "GET");
+ } catch ( AuthenticationErrorException ae ) {
+ return resp.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return resp.unavailable();
+ }
+ try {
+ resp.required( "clientId", id, "");
+ } catch ( RequiredFieldException rfe ) {
+ logger.debug( resp.toString() );
+ return Response.status(resp.getErr().getCode())
+ .entity( resp.getErr() )
+ .build();
+ }
+ MR_Client nClient = mr_clientService.getMr_Client( id, resp.getErr() );
+ if ( resp.getErr().is2xx()) {
+ return Response.ok(nClient)
+ .build();
+ }
+ return Response.status(resp.getErr().getCode())
+ .entity( resp.getErr() )
+ .build();
+ }
+}
diff --git a/src/main/java/org/openecomp/dmaapbc/resources/MR_ClusterResource.java b/src/main/java/org/openecomp/dmaapbc/resources/MR_ClusterResource.java
new file mode 100644
index 0000000..a7b8f37
--- /dev/null
+++ b/src/main/java/org/openecomp/dmaapbc/resources/MR_ClusterResource.java
@@ -0,0 +1,195 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OpenECOMP - org.openecomp.dmaapbc
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.dmaapbc.resources;
+
+import java.util.List;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.log4j.Logger;
+import org.openecomp.dmaapbc.authentication.AuthenticationErrorException;
+import org.openecomp.dmaapbc.model.MR_Cluster;
+import org.openecomp.dmaapbc.service.ApiService;
+import org.openecomp.dmaapbc.service.MR_ClusterService;
+
+
+@Path("/mr_clusters")
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+public class MR_ClusterResource {
+ static final Logger logger = Logger.getLogger(MR_ClusterResource.class);
+
+ MR_ClusterService mr_clusterService = new MR_ClusterService();
+
+ @GET
+ public List<MR_Cluster> getMr_Clusters(@Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth) {
+ ApiService resp = new ApiService();
+ try {
+ resp.checkAuthorization( basicAuth, uriInfo.getPath(), "GET");
+ } catch ( AuthenticationErrorException ae ) {
+ return null; //resp.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return null; //resp.unavailable();
+ }
+ return mr_clusterService.getAllMr_Clusters();
+ }
+
+ @POST
+ public Response addMr_Cluster( MR_Cluster cluster,
+ @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth) {
+ logger.info("Entry: /POST" );
+ ApiService resp = new ApiService();
+ try {
+ resp.checkAuthorization( basicAuth, uriInfo.getPath(), "POST");
+ } catch ( AuthenticationErrorException ae ) {
+ return resp.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return resp.unavailable();
+ }
+ try {
+ resp.required( "dcaeLocationName", cluster.getDcaeLocationName(), "" );
+ resp.required( "fqdn", cluster.getFqdn(), "" );
+ } catch( RequiredFieldException rfe ) {
+ return Response.status(resp.getErr().getCode())
+ .entity( resp.getErr() )
+ .build();
+ }
+ MR_Cluster mrc = mr_clusterService.addMr_Cluster(cluster, resp.getErr() );
+ if ( mrc != null && mrc.isStatusValid() ) {
+ return Response.status(Status.CREATED)
+ .entity(mrc)
+ .build();
+ }
+ return Response.status(resp.getErr().getCode())
+ .entity(resp.getErr())
+ .build();
+
+ }
+
+ @PUT
+ @Path("/{clusterId}")
+ public Response updateMr_Cluster( @PathParam("clusterId") String clusterId, MR_Cluster cluster,
+ @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth) {
+ ApiService resp = new ApiService();
+ try {
+ resp.checkAuthorization( basicAuth, uriInfo.getPathSegments().get(0).getPath(), "PUT");
+ } catch ( AuthenticationErrorException ae ) {
+ return resp.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return resp.unavailable();
+ }
+ try {
+ resp.required( "fqdn", clusterId, "" );
+ resp.required( "dcaeLocationName", cluster.getDcaeLocationName(), "" );
+ } catch( RequiredFieldException rfe ) {
+ return Response.status(resp.getErr().getCode())
+ .entity( resp.getErr() )
+ .build();
+ }
+ cluster.setDcaeLocationName(clusterId);
+ MR_Cluster mrc = mr_clusterService.updateMr_Cluster(cluster, resp.getErr() );
+ if ( mrc != null && mrc.isStatusValid() ) {
+ return Response.status(Status.CREATED)
+ .entity(mrc)
+ .build();
+ }
+ return Response.status(resp.getErr().getCode())
+ .entity(resp.getErr())
+ .build();
+ }
+
+ @DELETE
+ @Path("/{clusterId}")
+ public Response deleteMr_Cluster( @PathParam("clusterId") String id,
+ @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth){
+ ApiService resp = new ApiService();
+ try {
+ resp.checkAuthorization( basicAuth, uriInfo.getPathSegments().get(0).getPath(), "DELETE");
+ } catch ( AuthenticationErrorException ae ) {
+ return resp.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return resp.unavailable();
+ }
+ try {
+ resp.required( "fqdn", id, "" );
+ } catch( RequiredFieldException rfe ) {
+ return Response.status(resp.getErr().getCode())
+ .entity( resp.getErr() )
+ .build();
+ }
+ mr_clusterService.removeMr_Cluster(id, resp.getErr() );
+ if ( resp.getErr().is2xx()) {
+ return Response.status(Status.NO_CONTENT.getStatusCode())
+ .build();
+ }
+ return Response.status(resp.getErr().getCode())
+ .entity( resp.getErr() )
+ .build();
+ }
+
+ @GET
+ @Path("/{clusterId}")
+ public Response getMR_Cluster( @PathParam("clusterId") String id,
+ @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth) {
+ ApiService resp = new ApiService();
+ try {
+ resp.checkAuthorization( basicAuth, uriInfo.getPathSegments().get(0).getPath(), "GET");
+ } catch ( AuthenticationErrorException ae ) {
+ return resp.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return resp.unavailable();
+ }
+ try {
+ resp.required( "dcaeLocationName", id, "" );
+ } catch( RequiredFieldException rfe ) {
+ return Response.status(resp.getErr().getCode())
+ .entity( resp.getErr() )
+ .build();
+ }
+ MR_Cluster mrc = mr_clusterService.getMr_Cluster( id, resp.getErr() );
+ if ( mrc != null && mrc.isStatusValid() ) {
+ return Response.status(Status.CREATED)
+ .entity(mrc)
+ .build();
+ }
+ return Response.status(resp.getErr().getCode())
+ .entity(resp.getErr())
+ .build();
+ }
+}
diff --git a/src/main/java/org/openecomp/dmaapbc/resources/RequiredFieldException.java b/src/main/java/org/openecomp/dmaapbc/resources/RequiredFieldException.java
new file mode 100644
index 0000000..081e086
--- /dev/null
+++ b/src/main/java/org/openecomp/dmaapbc/resources/RequiredFieldException.java
@@ -0,0 +1,30 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OpenECOMP - org.openecomp.dmaapbc
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.dmaapbc.resources;
+
+public class RequiredFieldException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+}
diff --git a/src/main/java/org/openecomp/dmaapbc/resources/TopicResource.java b/src/main/java/org/openecomp/dmaapbc/resources/TopicResource.java
new file mode 100644
index 0000000..5d4b9a7
--- /dev/null
+++ b/src/main/java/org/openecomp/dmaapbc/resources/TopicResource.java
@@ -0,0 +1,184 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OpenECOMP - org.openecomp.dmaapbc
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.dmaapbc.resources;
+
+import java.util.List;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.log4j.Logger;
+import org.openecomp.dmaapbc.authentication.AuthenticationErrorException;
+import org.openecomp.dmaapbc.model.ApiError;
+import org.openecomp.dmaapbc.model.Topic;
+import org.openecomp.dmaapbc.service.ApiService;
+import org.openecomp.dmaapbc.service.TopicService;
+
+@Path("/topics")
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+public class TopicResource {
+
+ static final Logger logger = Logger.getLogger(TopicResource.class);
+
+ TopicService mr_topicService = new TopicService();
+
+ @GET
+ public List<Topic> getTopics(@Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth) {
+ logger.info("Entry: /GET" );
+ ApiService check = new ApiService();
+ try {
+ check.checkAuthorization( basicAuth, uriInfo.getPath(), "GET");
+ } catch ( AuthenticationErrorException ae ) {
+ return null; // check.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return null; //check.unavailable();
+ }
+ return mr_topicService.getAllTopics();
+ }
+
+ @POST
+ public Response addTopic( Topic topic, @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth ) {
+ logger.info("Entry: /POST" );
+ ApiService check = new ApiService();
+ try {
+ check.checkAuthorization( basicAuth, uriInfo.getPath(), "POST");
+ } catch ( AuthenticationErrorException ae ) {
+ return check.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return check.unavailable();
+ }
+ try {
+ check.required( "topicName", topic.getTopicName(), "^\\S+$" ); //no white space allowed in topicName
+ check.required( "topicDescription", topic.getTopicDescription(), "" );
+ check.required( "owner", topic.getOwner(), "" );
+ } catch( RequiredFieldException rfe ) {
+ return Response.status(check.getErr().getCode())
+ .entity( check.getErr() )
+ .build();
+ }
+ //String fqtn = Topic.genFqtn(topic.getTopicName());
+ ApiError err = check.getErr();
+
+ topic.setLastMod();
+
+ Topic mrc = mr_topicService.addTopic(topic, err);
+ if ( mrc != null && mrc.isStatusValid() ) {
+ return Response.status(Status.CREATED)
+ .entity(mrc)
+ .build();
+ }
+ return Response.status(err.getCode())
+ .entity(err)
+ .build();
+
+ }
+
+ @PUT
+ @Path("/{topicId}")
+ public Response updateTopic( @PathParam("topicId") String topicId, Topic topic, @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth ) {
+ logger.info("Entry: /PUT " + topic );
+ ApiError err = new ApiError();
+ err.setCode(Status.BAD_REQUEST.getStatusCode());
+ err.setMessage( "Method /PUT not supported for /topics");
+
+ return Response.status(err.getCode())
+ .entity( err )
+ .build();
+ //return mr_topicService.updateTopic(topic);
+ }
+
+ @DELETE
+ @Path("/{topicId}")
+ public Response deleteTopic( @PathParam("topicId") String id, @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth ){
+ logger.info("Entry: /DELETE " + id );
+ ApiService check = new ApiService();
+ try {
+ check.checkAuthorization( basicAuth, uriInfo.getPathSegments().get(0).getPath(), "DELETE");
+ } catch ( AuthenticationErrorException ae ) {
+ return check.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return check.unavailable();
+ }
+ try {
+ check.required( "fqtn", id, "" );
+ } catch( RequiredFieldException rfe ) {
+ return Response.status(check.getErr().getCode())
+ .entity( check.getErr() )
+ .build();
+ }
+
+ Topic topic = mr_topicService.removeTopic(id, check.getErr());
+ if ( check.getErr().is2xx()) {
+ return Response.status(Status.NO_CONTENT.getStatusCode())
+ .build();
+ }
+ return Response.status(check.getErr().getCode())
+ .entity( check.getErr() )
+ .build();
+ }
+
+
+ @GET
+ @Path("/{topicId}")
+ public Response getTopic( @PathParam("topicId") String id , @Context UriInfo uriInfo, @HeaderParam("Authorization") String basicAuth) {
+ logger.info("Entry: /GET " + id);
+ ApiService check = new ApiService();
+ try {
+ check.checkAuthorization( basicAuth, uriInfo.getPathSegments().get(0).getPath(), "GET");
+ } catch ( AuthenticationErrorException ae ) {
+ return check.unauthorized();
+ } catch ( Exception e ) {
+ logger.error( "Unexpected exception " + e );
+ return check.unavailable();
+ }
+ try {
+ check.required( "topicName", id, "^\\S+$" ); //no white space allowed in topicName
+ } catch( RequiredFieldException rfe ) {
+ return Response.status(check.getErr().getCode())
+ .entity( check.getErr() )
+ .build();
+ }
+ Topic mrc = mr_topicService.getTopic( id, check.getErr() );
+ if ( mrc == null ) {
+ return Response.status(check.getErr().getCode())
+ .entity(check.getErr())
+ .build();
+ }
+ return Response.ok(mrc)
+ .build();
+ }
+}