This is an automated email from the ASF dual-hosted git repository.

mradhakrishnan pushed a commit to branch AMBARI-24711
in repository https://gitbox.apache.org/repos/asf/ambari.git

commit f9d70515bad9e8d5f582e99409969f4cc2839587
Author: Jayush Luniya <[email protected]>
AuthorDate: Mon Jul 10 12:53:08 2017 -0700

    AMBARI-21077: Fix build issues after reverting patch for AMBARI-21077 and 
merging latest trunk (jluniya)
---
 .../server/api/services/MpackRequestSwagger.java   | 30 +++++++
 .../ambari/server/api/services/MpacksService.java  | 82 +++++++++++++++++--
 .../ambari/server/controller/MpackResponse.java    | 10 +++
 .../controller/internal/MpackResourceProvider.java | 19 +++--
 .../ambari/server/upgrade/UpgradeCatalog251.java   |  1 +
 .../server/api/services/MpacksServiceTest.java     | 93 ++++++++++++++++++++++
 6 files changed, 219 insertions(+), 16 deletions(-)

diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/api/services/MpackRequestSwagger.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/api/services/MpackRequestSwagger.java
new file mode 100644
index 0000000..5fe5693
--- /dev/null
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/api/services/MpackRequestSwagger.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.ambari.server.api.services;
+
+import org.apache.ambari.server.controller.ApiModel;
+import org.apache.ambari.server.controller.MpackRequest;
+import org.apache.ambari.server.controller.internal.MpackResourceProvider;
+
+import io.swagger.annotations.ApiModelProperty;
+
+@SuppressWarnings("unused") // for Swagger
+public interface MpackRequestSwagger extends ApiModel {
+  @ApiModelProperty(name = MpackResourceProvider.RESPONSE_KEY)
+  MpackRequest getMpackRequest();
+}
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/api/services/MpacksService.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/api/services/MpacksService.java
index 9912f88..32dae0f 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/api/services/MpacksService.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/api/services/MpacksService.java
@@ -20,7 +20,6 @@ package org.apache.ambari.server.api.services;
 import org.apache.ambari.server.api.resources.ResourceInstance;
 
 import org.apache.ambari.server.controller.spi.Resource;
-import org.apache.ambari.server.api.util.ApiVersion;
 import javax.ws.rs.GET;
 import javax.ws.rs.POST;
 import javax.ws.rs.Path;
@@ -28,19 +27,38 @@ import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 import java.util.Collections;
 
+
+import org.apache.ambari.server.api.resources.ResourceInstance;
+import org.apache.ambari.server.controller.MpackResponse.MpackResponseWrapper;
+import org.apache.ambari.server.controller.internal.MpackResourceProvider;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.http.HttpStatus;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+
+
 /**
  * Service for Mpacks Management.
  * Endpoint for Mpack Data
  */
-
+@Path("/mpacks/")
+@Api(value = "Mpacks", description = "Endpoint for mpack-specific operations")
 public class MpacksService extends BaseService {
 
-  public MpacksService(ApiVersion apiVersion) {
-    super(apiVersion);
+  private static final String MPACK_REQUEST_TYPE = 
"org.apache.ambari.server.api.services.MpackRequestSwagger";
+
+  public MpacksService() {
+    super();
   }
 
   /**
@@ -53,7 +71,28 @@ public class MpacksService extends BaseService {
    *
    */
   @GET
-  @Produces("text/plain")
+  @Produces(MediaType.TEXT_PLAIN)
+  @ApiOperation(value = "Returns all mpacks registered with this Ambari 
instance",
+    response = MpackResponseWrapper.class, responseContainer = 
RESPONSE_CONTAINER_LIST)
+  @ApiImplicitParams({
+    @ApiImplicitParam(name = QUERY_FIELDS, value = QUERY_FILTER_DESCRIPTION, 
dataType = DATA_TYPE_STRING,
+      paramType = PARAM_TYPE_QUERY, defaultValue = 
MpackResourceProvider.MPACK_ID),
+    @ApiImplicitParam(name = QUERY_SORT, value = QUERY_SORT_DESCRIPTION, 
dataType = DATA_TYPE_STRING,
+      paramType = PARAM_TYPE_QUERY),
+    @ApiImplicitParam(name = QUERY_PAGE_SIZE, value = 
QUERY_PAGE_SIZE_DESCRIPTION, defaultValue = DEFAULT_PAGE_SIZE,
+      dataType = DATA_TYPE_INT, paramType = PARAM_TYPE_QUERY),
+    @ApiImplicitParam(name = QUERY_FROM, value = QUERY_FROM_DESCRIPTION, 
allowableValues = QUERY_FROM_VALUES,
+      defaultValue = DEFAULT_FROM, dataType = DATA_TYPE_INT, paramType = 
PARAM_TYPE_QUERY),
+    @ApiImplicitParam(name = QUERY_TO, value = QUERY_TO_DESCRIPTION, 
allowableValues = QUERY_TO_VALUES,
+      dataType = DATA_TYPE_INT, paramType = PARAM_TYPE_QUERY),
+  })
+  @ApiResponses({
+    @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION),
+    @ApiResponse(code = HttpStatus.SC_NOT_FOUND, message = 
MSG_RESOURCE_NOT_FOUND),
+    @ApiResponse(code = HttpStatus.SC_UNAUTHORIZED, message = 
MSG_NOT_AUTHENTICATED),
+    @ApiResponse(code = HttpStatus.SC_FORBIDDEN, message = 
MSG_PERMISSION_DENIED),
+    @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = 
MSG_SERVER_ERROR),
+  })
   public Response getMpacks(String body, @Context HttpHeaders headers, 
@Context UriInfo ui) {
     return handleRequest(headers, body, ui, Request.Type.GET,
             createMpackResource(null));
@@ -68,7 +107,20 @@ public class MpacksService extends BaseService {
    * @return information regarding the created mpack
    */
   @POST
-  @Produces("text/plain")
+  @Produces(MediaType.TEXT_PLAIN)
+  @ApiOperation(value = "Registers an mpack with this Ambari mpack")
+  @ApiImplicitParams({
+    @ApiImplicitParam(dataType = MPACK_REQUEST_TYPE, paramType = 
PARAM_TYPE_BODY)
+  })
+  @ApiResponses({
+    @ApiResponse(code = HttpStatus.SC_CREATED, message = 
MSG_SUCCESSFUL_OPERATION),
+    @ApiResponse(code = HttpStatus.SC_ACCEPTED, message = 
MSG_REQUEST_ACCEPTED),
+    @ApiResponse(code = HttpStatus.SC_BAD_REQUEST, message = 
MSG_INVALID_ARGUMENTS),
+    @ApiResponse(code = HttpStatus.SC_CONFLICT, message = 
MSG_RESOURCE_ALREADY_EXISTS),
+    @ApiResponse(code = HttpStatus.SC_UNAUTHORIZED, message = 
MSG_NOT_AUTHENTICATED),
+    @ApiResponse(code = HttpStatus.SC_FORBIDDEN, message = 
MSG_PERMISSION_DENIED),
+    @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = 
MSG_SERVER_ERROR),
+  })
   public Response createMpacks(String body, @Context HttpHeaders headers, 
@Context UriInfo ui) {
     return handleRequest(headers, body, ui, Request.Type.POST, 
createMpackResource(null));
   }
@@ -81,8 +133,22 @@ public class MpacksService extends BaseService {
    */
   @GET
   @Path("{mpack_id}")
-  @Produces("text/plain")
-  public Response getMpack(String body, @Context HttpHeaders headers, @Context 
UriInfo ui, @PathParam("mpack_id") String mpackId) {
+  @Produces(MediaType.TEXT_PLAIN)
+  @ApiOperation(value = "Returns information about a specific mpack that is 
registered with this Ambari instance",
+    response = MpackResponseWrapper.class)
+  @ApiImplicitParams({
+    @ApiImplicitParam(name = QUERY_FIELDS, value = QUERY_FILTER_DESCRIPTION, 
dataType = DATA_TYPE_STRING,
+      paramType = PARAM_TYPE_QUERY, defaultValue = 
MpackResourceProvider.ALL_PROPERTIES),
+  })
+  @ApiResponses({
+    @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION),
+    @ApiResponse(code = HttpStatus.SC_NOT_FOUND, message = 
MSG_RESOURCE_NOT_FOUND),
+    @ApiResponse(code = HttpStatus.SC_UNAUTHORIZED, message = 
MSG_NOT_AUTHENTICATED),
+    @ApiResponse(code = HttpStatus.SC_FORBIDDEN, message = 
MSG_PERMISSION_DENIED),
+    @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = 
MSG_SERVER_ERROR),
+  })
+  public Response getMpack(String body, @Context HttpHeaders headers, @Context 
UriInfo ui,
+    @PathParam("mpack_id") String mpackId) {
 
     return handleRequest(headers, body, ui, Request.Type.GET,
             createMpackResource(mpackId));
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/MpackResponse.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/MpackResponse.java
index d111913..16eb03c 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/MpackResponse.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/MpackResponse.java
@@ -17,7 +17,11 @@
  */
 package org.apache.ambari.server.controller;
 
+
 import org.apache.ambari.server.state.Mpacks;
+import org.apache.ambari.server.controller.internal.MpackResourceProvider;
+
+import io.swagger.annotations.ApiModelProperty;
 
 /**
  * Represents a mpack response.
@@ -106,4 +110,10 @@ public class MpackResponse {
     MpackResponse MpackResponse = (MpackResponse) obj;
     return getMpackId().equals(MpackResponse.getMpackId());
   }
+
+  public interface MpackResponseWrapper extends ApiModel {
+    @ApiModelProperty(name = MpackResourceProvider.RESPONSE_KEY)
+    @SuppressWarnings("unused")
+    MpackResponse getMpackResponse();
+  }
 }
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/MpackResourceProvider.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/MpackResourceProvider.java
index 6f90e04..f939da7 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/MpackResourceProvider.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/MpackResourceProvider.java
@@ -44,6 +44,7 @@ import 
org.apache.ambari.server.controller.AmbariManagementController;
 import org.apache.ambari.server.controller.MpackResponse;
 import org.apache.ambari.server.controller.MpackRequest;
 import org.apache.ambari.server.controller.utilities.PredicateHelper;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
 import org.apache.ambari.server.orm.dao.MpackDAO;
 import org.apache.ambari.server.orm.dao.StackDAO;
 import org.apache.ambari.server.orm.entities.MpackEntity;
@@ -56,14 +57,16 @@ import org.apache.ambari.server.state.Packlet;
 @StaticallyInject
 public class MpackResourceProvider extends AbstractControllerResourceProvider {
 
-  public static final String MPACK_ID = "MpackInfo/mpack_id";
-  public static final String REGISTRY_ID = "MpackInfo/registry_id";
-  public static final String MPACK_NAME = "MpackInfo/mpack_name";
-  public static final String MPACK_VERSION = "MpackInfo/mpack_version";
-  public static final String MPACK_URI = "MpackInfo/mpack_uri";
-  public static final String PACKLETS = "MpackInfo/packlets";
-  public static final String STACK_NAME_PROPERTY_ID = "MpackInfo/stack_name";
-  public static final String STACK_VERSION_PROPERTY_ID = 
"MpackInfo/stack_version";
+  public static final String RESPONSE_KEY = "MpackInfo";
+  public static final String ALL_PROPERTIES = RESPONSE_KEY + 
PropertyHelper.EXTERNAL_PATH_SEP + "*";
+  public static final String MPACK_ID = RESPONSE_KEY + 
PropertyHelper.EXTERNAL_PATH_SEP + "mpack_id";
+  public static final String REGISTRY_ID = RESPONSE_KEY + 
PropertyHelper.EXTERNAL_PATH_SEP + "registry_id";
+  public static final String MPACK_NAME = RESPONSE_KEY + 
PropertyHelper.EXTERNAL_PATH_SEP + "mpack_name";
+  public static final String MPACK_VERSION = RESPONSE_KEY + 
PropertyHelper.EXTERNAL_PATH_SEP + "mpack_version";
+  public static final String MPACK_URI = RESPONSE_KEY + 
PropertyHelper.EXTERNAL_PATH_SEP + "mpack_uri";
+  public static final String PACKLETS = RESPONSE_KEY + 
PropertyHelper.EXTERNAL_PATH_SEP + "packlets";
+  public static final String STACK_NAME_PROPERTY_ID = RESPONSE_KEY + 
PropertyHelper.EXTERNAL_PATH_SEP + "stack_name";
+  public static final String STACK_VERSION_PROPERTY_ID = RESPONSE_KEY + 
PropertyHelper.EXTERNAL_PATH_SEP + "stack_version";
 
   private static Set<String> pkPropertyIds = new HashSet<>(
           Arrays.asList(MPACK_ID, STACK_NAME_PROPERTY_ID, 
STACK_VERSION_PROPERTY_ID));
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog251.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog251.java
index 07c7d3e..6200915 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog251.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog251.java
@@ -31,6 +31,7 @@ import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Config;
 import org.apache.ambari.server.state.SecurityType;
 import org.apache.commons.lang.StringUtils;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/api/services/MpacksServiceTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/api/services/MpacksServiceTest.java
new file mode 100644
index 0000000..3c3184c
--- /dev/null
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/api/services/MpacksServiceTest.java
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.ambari.server.api.services;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.ambari.server.api.resources.ResourceInstance;
+import org.apache.ambari.server.api.services.parsers.RequestBodyParser;
+import org.apache.ambari.server.api.services.serializers.ResultSerializer;
+
+import org.apache.ambari.server.controller.spi.Resource;
+
+/**
+ * Unit tests for MpacksService
+ */
+public class MpacksServiceTest extends BaseServiceTest{
+  @Override
+  public List<BaseServiceTest.ServiceTestInvocation> getTestInvocations() 
throws Exception {
+    List<BaseServiceTest.ServiceTestInvocation> listInvocations = new 
ArrayList<>();
+
+    // getMpacks
+    MpacksService service = new TestMpacksService("null");
+    Method m = service.getClass().getMethod("getMpacks", String.class, 
HttpHeaders.class, UriInfo.class);
+    Object[] args = new Object[]{null, getHttpHeaders(), getUriInfo()};
+    listInvocations.add(new ServiceTestInvocation(Request.Type.GET, service, 
m, args, null));
+
+    // getMpack
+    service = new TestMpacksService("1");
+    m = service.getClass().getMethod("getMpack", String.class, 
HttpHeaders.class, UriInfo.class, String.class);
+    args = new Object[]{null, getHttpHeaders(), getUriInfo(), ""};
+    listInvocations.add(new ServiceTestInvocation(Request.Type.GET, service, 
m, args, null));
+
+    //createMpacks
+    service = new TestMpacksService(null);
+    m = service.getClass().getMethod("createMpacks", String.class, 
HttpHeaders.class, UriInfo.class);
+    args = new Object[]{"body", getHttpHeaders(), getUriInfo()};
+    listInvocations.add(new ServiceTestInvocation(Request.Type.POST, service, 
m, args, "body"));
+
+    return listInvocations;
+  }
+  private class TestMpacksService extends MpacksService {
+
+    private String m_mpackId;
+
+    private TestMpacksService(String mpackId) {
+      super();
+      m_mpackId = mpackId;
+    }
+
+    @Override
+    protected ResourceInstance createResource(Resource.Type type, 
Map<Resource.Type, String> mapIds) {
+      return getTestResource();
+    }
+
+    @Override
+    RequestFactory getRequestFactory() {
+      return getTestRequestFactory();
+    }
+
+    @Override
+    protected RequestBodyParser getBodyParser() {
+      return getTestBodyParser();
+    }
+
+    @Override
+    protected ResultSerializer getResultSerializer() {
+      return getTestResultSerializer();
+    }
+  }
+
+
+}

Reply via email to