You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ad...@apache.org on 2017/05/23 10:34:16 UTC
[18/49] ambari git commit: AMBARI-20436. Create a prototype of
ambari-server swagger integration. (jaimin)
http://git-wip-us.apache.org/repos/asf/ambari/blob/fb86fb3b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ViewDataMigrationService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ViewDataMigrationService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ViewDataMigrationService.java
deleted file mode 100644
index 2a9aa64..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ViewDataMigrationService.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/**
- * 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 javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Response;
-
-import org.apache.ambari.server.orm.entities.ViewInstanceEntity;
-import org.apache.ambari.server.view.ViewDataMigrationUtility;
-import org.apache.ambari.server.view.ViewRegistry;
-import org.apache.ambari.view.migration.ViewDataMigrationException;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * Service responsible for data migration between view instances.
- */
-public class ViewDataMigrationService extends BaseService {
- /**
- * Logger.
- */
- private static final Log LOG = LogFactory.getLog(ViewDataMigrationService.class);
-
- /**
- * The current view name.
- */
- private final String viewName;
-
- /**
- * The current view version.
- */
- private final String viewVersion;
-
- /**
- * The current view instance name.
- */
- private final String instanceName;
-
- /**
- * The singleton view registry.
- */
- ViewRegistry viewRegistry;
-
- /**
- * The view data migration utility.
- */
- private ViewDataMigrationUtility viewDataMigrationUtility;
-
- /**
- * Constructor.
- *
- * @param viewName the current view name
- * @param viewVersion the current view version
- * @param instanceName the current view instance name
- */
- public ViewDataMigrationService(String viewName, String viewVersion, String instanceName) {
- this.viewName = viewName;
- this.viewVersion = viewVersion;
- this.instanceName = instanceName;
- this.viewRegistry = ViewRegistry.getInstance();
- }
-
- /**
- * Migrates view instance persistence data from origin view instance
- * specified in the path params.
- *
- * @param originViewVersion the origin view version
- * @param originInstanceName the origin view instance name
- */
- @PUT
- @Path("{originVersion}/{originInstanceName}")
- public Response migrateData(@PathParam("originVersion") String originViewVersion,
- @PathParam("originInstanceName") String originInstanceName)
- throws ViewDataMigrationException {
-
- if (!viewRegistry.checkAdmin()) {
- throw new WebApplicationException(Response.Status.FORBIDDEN);
- }
-
- LOG.info("Data Migration to view instance " + viewName + "/" + viewVersion + "/" + instanceName +
- " from " + viewName + "/" + originViewVersion + "/" + originInstanceName);
-
- ViewInstanceEntity instanceDefinition = viewRegistry.getInstanceDefinition(
- viewName, viewVersion, instanceName);
- ViewInstanceEntity originInstanceDefinition = viewRegistry.getInstanceDefinition(
- viewName, originViewVersion, originInstanceName);
-
- getViewDataMigrationUtility().migrateData(instanceDefinition, originInstanceDefinition, false);
-
- Response.ResponseBuilder builder = Response.status(Response.Status.OK);
- return builder.build();
- }
-
- protected ViewDataMigrationUtility getViewDataMigrationUtility() {
- if (viewDataMigrationUtility == null) {
- viewDataMigrationUtility = new ViewDataMigrationUtility(viewRegistry);
- }
- return viewDataMigrationUtility;
- }
-
- protected void setViewDataMigrationUtility(ViewDataMigrationUtility viewDataMigrationUtility) {
- this.viewDataMigrationUtility = viewDataMigrationUtility;
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/fb86fb3b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ViewExternalSubResourceService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ViewExternalSubResourceService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ViewExternalSubResourceService.java
deleted file mode 100644
index 66ccae7..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ViewExternalSubResourceService.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/**
- * 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.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.ws.rs.GET;
-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.HttpHeaders;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
-
-import org.apache.ambari.server.api.resources.ResourceInstance;
-import org.apache.ambari.server.controller.spi.Resource;
-import org.apache.ambari.server.orm.entities.ViewEntity;
-import org.apache.ambari.server.orm.entities.ViewInstanceEntity;
-
-/**
- * Service responsible for view sub-resource requests.
- */
-public class ViewExternalSubResourceService extends BaseService {
-
- /**
- * The resource type.
- */
- private final Resource.Type type;
-
- /**
- * The view name.
- */
- private final String viewName;
-
- /**
- * The view version.
- */
- private final String version;
-
- /**
- * The instance name.
- */
- private final String instanceName;
-
- /**
- * Mapping of resource names to services.
- */
- private final Map<String, Object> resourceServiceMap = new HashMap<String, Object>();
-
-
- // ----- Constructors ------------------------------------------------------
-
- public ViewExternalSubResourceService(Resource.Type type, ViewInstanceEntity viewInstanceDefinition) {
- ViewEntity viewEntity = viewInstanceDefinition.getViewEntity();
-
- this.type = type;
- this.viewName = viewEntity.getCommonName();
- this.version = viewEntity.getVersion();
- this.instanceName = viewInstanceDefinition.getName();
- }
-
- /**
- * Handles URL: /resources
- * Get all external resources for a view.
- *
- * @param headers http headers
- * @param ui uri info
- *
- * @return instance collection resource representation
- */
- @GET
- @Produces("text/plain")
- public Response getResources(String body, @Context HttpHeaders headers, @Context UriInfo ui) {
- return handleRequest(headers, body, ui, Request.Type.GET,
- createResource(viewName, instanceName));
- }
-
- /**
- * Handles: GET /resources/{resourceName} Get a specific external resource.
- *
- * @param resourceName resource name
- *
- * @return resource service instance representation
- *
- * @throws IllegalArgumentException if the given resource name is unknown
- */
- @Path("{resourceName}")
- public Object getResource(@PathParam("resourceName") String resourceName) throws IOException {
-
- Object service = resourceServiceMap.get(resourceName);
- if (service == null) {
- throw new IllegalArgumentException("A resource type " + resourceName + " for view instance " +
- viewName + "/" + instanceName + " can not be found.");
- }
-
- return service;
- }
-
-
- // ----- helper methods ----------------------------------------------------
-
- /**
- * Register a sub-resource service.
- *
- * @param resourceName the resource name
- * @param service the service
- */
- public void addResourceService(String resourceName, Object service) {
- resourceServiceMap.put(resourceName, service);
- }
-
- /**
- * Create an view instance resource.
- *
- * @param viewName view name
- * @param instanceName instance name
- *
- * @return a view instance resource
- */
- private ResourceInstance createResource(String viewName, String instanceName) {
- Map<Resource.Type,String> mapIds = new HashMap<Resource.Type, String>();
- mapIds.put(Resource.Type.View, viewName);
- mapIds.put(Resource.Type.ViewVersion, version);
- mapIds.put(Resource.Type.ViewInstance, instanceName);
- return createResource(type, mapIds);
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/fb86fb3b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ViewInstanceService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ViewInstanceService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ViewInstanceService.java
deleted file mode 100644
index 53d4918..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ViewInstanceService.java
+++ /dev/null
@@ -1,282 +0,0 @@
-/*
- * 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.util.HashMap;
-import java.util.Map;
-
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-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.WebApplicationException;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
-
-import org.apache.ambari.server.api.resources.ResourceInstance;
-import org.apache.ambari.server.controller.spi.Resource;
-import org.apache.ambari.server.orm.entities.ViewInstanceEntity;
-import org.apache.ambari.server.security.authorization.AuthorizationException;
-import org.apache.ambari.server.view.ViewRegistry;
-
-/**
- * Service responsible for instances resource requests.
- */
-public class ViewInstanceService extends BaseService {
- /**
- * Parent view name.
- */
- private final String viewName;
-
- /**
- * The view version.
- */
- private final String version;
-
- /**
- * The view registry;
- */
- private final ViewRegistry viewRegistry;
-
- // ----- Constructors ------------------------------------------------------
-
- /**
- * Construct a view instance service.
- *
- * @param viewName the view id
- * @param version the version
- */
- public ViewInstanceService(String viewName, String version) {
- this.viewName = viewName;
- this.version = version;
-
- viewRegistry = ViewRegistry.getInstance();
- }
-
-
- // ----- ViewInstanceService -----------------------------------------------
-
- /**
- * Handles URL: /views/{viewID}/instances/{instanceID}
- * Get a specific instance.
- *
- * @param headers http headers
- * @param ui uri info
- * @param instanceName instance id
- *
- * @return instance resource representation
- */
- @GET
- @Path("{instanceName}")
- @Produces("text/plain")
- public Response getService(String body, @Context HttpHeaders headers, @Context UriInfo ui,
- @PathParam("instanceName") String instanceName) throws AuthorizationException {
- return handleRequest(headers, body, ui, Request.Type.GET, createResource(viewName, version, instanceName));
- }
-
- /**
- * Handles URL: /views/{viewID}/instances
- * Get all instances for a view.
- *
- * @param headers http headers
- * @param ui uri info
- *
- * @return instance collection resource representation
- */
- @GET
- @Produces("text/plain")
- public Response getServices(String body, @Context HttpHeaders headers, @Context UriInfo ui) throws AuthorizationException {
- return handleRequest(headers, body, ui, Request.Type.GET, createResource(viewName, version, null));
- }
-
- /**
- * Handles: POST /views/{viewID}/instances/{instanceId}
- * Create a specific instance.
- *
- * @param body http body
- * @param headers http headers
- * @param ui uri info
- * @param instanceName instance id
- *
- * @return information regarding the created instance
- */
- @POST
- @Path("{instanceName}")
- @Produces("text/plain")
- public Response createService(String body, @Context HttpHeaders headers, @Context UriInfo ui,
- @PathParam("instanceName") String instanceName) throws AuthorizationException {
- return handleRequest(headers, body, ui, Request.Type.POST, createResource(viewName, version, instanceName));
- }
-
- /**
- * Handles: POST /views/{viewID}/instances
- * Create multiple instances.
- *
- * @param body http body
- * @param headers http headers
- * @param ui uri info
- *
- * @return information regarding the created instances
- */
- @POST
- @Produces("text/plain")
- public Response createServices(String body, @Context HttpHeaders headers, @Context UriInfo ui) throws AuthorizationException {
- return handleRequest(headers, body, ui, Request.Type.POST, createResource(viewName, version, null));
- }
-
- /**
- * Handles: PUT /views/{viewID}/instances/{instanceId}
- * Update a specific instance.
- *
- * @param body http body
- * @param headers http headers
- * @param ui uri info
- * @param instanceName instance id
- *
- * @return information regarding the updated instance
- */
- @PUT
- @Path("{instanceName}")
- @Produces("text/plain")
- public Response updateService(String body, @Context HttpHeaders headers, @Context UriInfo ui,
- @PathParam("instanceName") String instanceName) throws AuthorizationException {
- return handleRequest(headers, body, ui, Request.Type.PUT, createResource(viewName, version, instanceName));
- }
-
- /**
- * Handles: PUT /views/{viewID}/instances
- * Update multiple instances.
- *
- * @param body http body
- * @param headers http headers
- * @param ui uri info
- *
- * @return information regarding the updated instance
- */
- @PUT
- @Produces("text/plain")
- public Response updateServices(String body, @Context HttpHeaders headers, @Context UriInfo ui) throws AuthorizationException {
- return handleRequest(headers, body, ui, Request.Type.PUT, createResource(viewName, version, null));
- }
-
- /**
- * Handles: DELETE /views/{viewID}/instances/{instanceId}
- * Delete a specific instance.
- *
- * @param headers http headers
- * @param ui uri info
- * @param instanceName instance id
- *
- * @return information regarding the deleted instance
- */
- @DELETE
- @Path("{instanceName}")
- @Produces("text/plain")
- public Response deleteService(@Context HttpHeaders headers, @Context UriInfo ui,
- @PathParam("instanceName") String instanceName) throws AuthorizationException {
- return handleRequest(headers, null, ui, Request.Type.DELETE, createResource(viewName, version, instanceName));
- }
-
- /**
- * Get the sub-resource
- *
- * @param instanceName the instance id
- *
- * @return the service
- */
- @Path("{instanceName}/{resources}")
- public Object getResourceHandler(@Context javax.ws.rs.core.Request request,
- @PathParam("instanceName") String instanceName,
- @PathParam("resources") String resources) {
-
- hasPermission(Request.Type.valueOf(request.getMethod()), instanceName);
-
- ViewInstanceEntity instanceDefinition =
- ViewRegistry.getInstance().getInstanceDefinition(viewName, version, instanceName);
-
- if (instanceDefinition == null) {
- throw new IllegalArgumentException("A view instance " +
- viewName + "/" + instanceName + " can not be found.");
- }
-
- Object service = instanceDefinition.getService(resources);
-
- if (service == null) {
- throw new IllegalArgumentException("A resource type " + resources + " for view instance " +
- viewName + "/" + instanceName + " can not be found.");
- }
- return service;
- }
-
- /**
- * Gets the admin privilege service
- */
- @Path("{instanceName}/privileges")
- public PrivilegeService getPrivilegeService(@Context javax.ws.rs.core.Request request,
- @PathParam ("instanceName") String instanceName) {
-
- hasPermission(Request.Type.valueOf(request.getMethod()), instanceName);
-
- return new ViewPrivilegeService(viewName, version, instanceName);
- }
-
- @Path("{instanceName}/migrate")
- public ViewDataMigrationService migrateData(@Context javax.ws.rs.core.Request request,
- @PathParam ("instanceName") String instanceName) {
- return new ViewDataMigrationService(viewName, version, instanceName);
- }
- // ----- helper methods ----------------------------------------------------
-
- /**
- * Create an view instance resource.
- *
- * @param viewName view name
- * @param instanceName instance name
- *
- * @return a view instance resource
- */
- private ResourceInstance createResource(String viewName, String viewVersion, String instanceName) {
- Map<Resource.Type, String> mapIds = new HashMap<Resource.Type, String>();
- mapIds.put(Resource.Type.View, viewName);
- mapIds.put(Resource.Type.ViewVersion, viewVersion);
- mapIds.put(Resource.Type.ViewInstance, instanceName);
- return createResource(Resource.Type.ViewInstance, mapIds);
- }
-
- /**
- * Determine whether or not the access specified by the given request type
- * is permitted for the current user on the view instance resource identified
- * by the given instance name.
- *
- * @param requestType the request method type
- * @param instanceName the name of the view instance resource
- *
- * @throws WebApplicationException if access is forbidden
- */
- private void hasPermission(Request.Type requestType, String instanceName) {
- if (!viewRegistry.checkPermission(viewName, version, instanceName, requestType == Request.Type.GET)) {
- throw new WebApplicationException(Response.Status.FORBIDDEN);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/fb86fb3b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ViewPermissionService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ViewPermissionService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ViewPermissionService.java
deleted file mode 100644
index 8f7f4ef..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ViewPermissionService.java
+++ /dev/null
@@ -1,186 +0,0 @@
-/**
- * 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.util.HashMap;
-import java.util.Map;
-
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-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.HttpHeaders;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
-
-import org.apache.ambari.server.api.resources.ResourceInstance;
-import org.apache.ambari.server.controller.spi.Resource;
-
-
-/**
- * Service responsible for custom view permission resource requests.
- */
-public class ViewPermissionService extends BaseService {
-
- /**
- * Parent view name.
- */
- private final String viewName;
-
- /**
- * The view version.
- */
- private final String version;
-
-
- // ----- Constructors ------------------------------------------------------
-
- /**
- * Construct a view permission service.
- *
- * @param viewName the view id
- * @param version the version
- */
- public ViewPermissionService(String viewName, String version) {
- this.viewName = viewName;
- this.version = version;
- }
-
-
- // ----- ViewPermissionService -----------------------------------------------
-
- /**
- * Handles: GET /permissions/{permissionID}
- * Get a specific permission.
- *
- * @param headers http headers
- * @param ui uri info
- * @param permissionId permission id
- *
- * @return permission instance representation
- */
- @GET
- @Path("{permissionId}")
- @Produces("text/plain")
- public Response getPermission(@Context HttpHeaders headers, @Context UriInfo ui,
- @PathParam("permissionId") String permissionId) {
-
- return handleRequest(headers, null, ui, Request.Type.GET, createPermissionResource(
- viewName, version, permissionId));
- }
-
- /**
- * Handles: GET /permissions
- * Get all permissions.
- *
- * @param headers http headers
- * @param ui uri info
- *
- * @return permission collection resource representation
- */
- @GET
- @Produces("text/plain")
- public Response getPermissions(@Context HttpHeaders headers, @Context UriInfo ui) {
- return handleRequest(headers, null, ui, Request.Type.GET, createPermissionResource(
- viewName, version, null));
- }
-
- /**
- * Handles: POST /permissions/{permissionID}
- * Create a specific permission.
- *
- * @param headers http headers
- * @param ui uri info
- * @param permissionId permission id
- *
- * @return information regarding the created permission
- */
- @POST
- @Path("{permissionId}")
- @Produces("text/plain")
- public Response createPermission(String body, @Context HttpHeaders headers, @Context UriInfo ui,
- @PathParam("permissionId") String permissionId) {
-
- return handleRequest(headers, body, ui, Request.Type.POST, createPermissionResource(
- viewName, version, permissionId));
- }
-
- /**
- * Handles: PUT /permissions/{permissionID}
- * Update a specific permission.
- *
- * @param headers http headers
- * @param ui uri info
- * @param permissionId permission id
- *
- * @return information regarding the updated permission
- */
- @PUT
- @Path("{permissionId}")
- @Produces("text/plain")
- public Response updatePermission(String body, @Context HttpHeaders headers, @Context UriInfo ui,
- @PathParam("permissionId") String permissionId) {
-
- return handleRequest(headers, body, ui, Request.Type.PUT, createPermissionResource(
- viewName, version, permissionId));
- }
-
- /**
- * Handles: DELETE /permissions/{permissionID}
- * Delete a specific permission.
- *
- * @param headers http headers
- * @param ui uri info
- * @param permissionId permission id
- *
- * @return information regarding the deleted permission
- */
- @DELETE
- @Path("{permissionId}")
- @Produces("text/plain")
- public Response deletePermission(@Context HttpHeaders headers, @Context UriInfo ui,
- @PathParam("permissionId") String permissionId) {
-
- return handleRequest(headers, null, ui, Request.Type.DELETE, createPermissionResource(
- viewName, version, permissionId));
- }
-
-
- // ----- helper methods ----------------------------------------------------
-
- /**
- * Create a permission resource.
- *
- * @param permissionId permission name
- *
- * @return a permission resource instance
- */
- protected ResourceInstance createPermissionResource(String viewName, String viewVersion, String permissionId) {
- Map<Resource.Type,String> mapIds = new HashMap<Resource.Type, String>();
- mapIds.put(Resource.Type.View, viewName);
- mapIds.put(Resource.Type.ViewVersion, viewVersion);
- mapIds.put(Resource.Type.ViewPermission, permissionId);
-
- return createResource(Resource.Type.ViewPermission, mapIds);
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/fb86fb3b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ViewPrivilegeService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ViewPrivilegeService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ViewPrivilegeService.java
deleted file mode 100644
index 7393745..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ViewPrivilegeService.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- * 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 privileges and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.api.services;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.ambari.server.api.resources.ResourceInstance;
-import org.apache.ambari.server.controller.spi.Resource;
-
-/**
- * Service responsible for view privilege resource requests.
- */
-public class ViewPrivilegeService extends PrivilegeService {
-
- private final String viewName;
- private final String viewVersion;
- private final String instanceName;
-
- public ViewPrivilegeService(String viewName, String viewVersion, String instanceName) {
- this.viewName = viewName;
- this.viewVersion = viewVersion;
- this.instanceName = instanceName;
- }
-
- // ----- PrivilegeService --------------------------------------------------
-
- @Override
- protected ResourceInstance createPrivilegeResource(String privilegeId) {
- Map<Resource.Type,String> mapIds = new HashMap<Resource.Type, String>();
- mapIds.put(Resource.Type.View, viewName);
- mapIds.put(Resource.Type.ViewVersion, viewVersion);
- mapIds.put(Resource.Type.ViewInstance, instanceName);
- mapIds.put(Resource.Type.ViewPrivilege, privilegeId);
-
- return createResource(Resource.Type.ViewPrivilege, mapIds);
- }
-}
-
http://git-wip-us.apache.org/repos/asf/ambari/blob/fb86fb3b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ViewService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ViewService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ViewService.java
deleted file mode 100644
index 17a9f34..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ViewService.java
+++ /dev/null
@@ -1,162 +0,0 @@
-/**
- * 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.util.Collections;
-
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-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.HttpHeaders;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
-
-import org.apache.ambari.server.api.resources.ResourceInstance;
-import org.apache.ambari.server.controller.spi.Resource;
-
-
-/**
- * Service responsible for view resource requests.
- */
-@Path("/views/")
-public class ViewService extends BaseService {
-
- /**
- * Handles: GET /views/{viewID}
- * Get a specific view.
- *
- * @param headers http headers
- * @param ui uri info
- * @param viewName view id
- *
- * @return view instance representation
- */
- @GET
- @Path("{viewName}")
- @Produces("text/plain")
- public Response getView(String body, @Context HttpHeaders headers, @Context UriInfo ui,
- @PathParam("viewName") String viewName) {
-
- return handleRequest(headers, body, ui, Request.Type.GET, createViewResource(viewName));
- }
-
- /**
- * Handles: GET /views
- * Get all views.
- *
- * @param headers http headers
- * @param ui uri info
- *
- * @return view collection resource representation
- */
- @GET
- @Produces("text/plain")
- public Response getViews(String body, @Context HttpHeaders headers, @Context UriInfo ui) {
- return handleRequest(headers, body, ui, Request.Type.GET, createViewResource(null));
- }
-
- /**
- * Handles: POST /views/{viewID}
- * Create a specific view.
- *
- * @param headers http headers
- * @param ui uri info
- * @param viewName view id
- *
- * @return information regarding the created view
- */
- @POST
- @Path("{viewName}")
- @Produces("text/plain")
- public Response createView(String body, @Context HttpHeaders headers, @Context UriInfo ui,
- @PathParam("viewName") String viewName) {
-
- return handleRequest(headers, body, ui, Request.Type.POST, createViewResource(viewName));
- }
-
- /**
- * Handles: PUT /views/{viewID}
- * Update a specific view.
- *
- * @param headers http headers
- * @param ui uri info
- * @param viewName view id
- *
- * @return information regarding the updated view
- */
- @PUT
- @Path("{viewName}")
- @Produces("text/plain")
- public Response updateView(String body, @Context HttpHeaders headers, @Context UriInfo ui,
- @PathParam("viewName") String viewName) {
-
- return handleRequest(headers, body, ui, Request.Type.PUT, createViewResource(viewName));
- }
-
- /**
- * Handles: DELETE /views/{viewID}
- * Delete a specific view.
- *
- * @param headers http headers
- * @param ui uri info
- * @param viewName view id
- *
- * @return information regarding the deleted view
- */
- @DELETE
- @Path("{viewName}")
- @Produces("text/plain")
- public Response deleteView(@Context HttpHeaders headers, @Context UriInfo ui,
- @PathParam("viewName") String viewName) {
-
- return handleRequest(headers, null, ui, Request.Type.DELETE, createViewResource(viewName));
- }
-
- /**
- * Get the instances sub-resource
- *
- * @param viewName view id
- *
- * @return the versions service
- */
- @Path("{viewName}/versions")
- public ViewVersionService getInstanceHandler(@PathParam("viewName") String viewName) {
- return new ViewVersionService(viewName);
- }
-
-
- // ----- helper methods ----------------------------------------------------
-
- /**
- * Create a view resource.
- *
- * @param viewName view name
- *
- * @return a view resource instance
- */
- private ResourceInstance createViewResource(String viewName) {
- return createResource(Resource.Type.View,
- Collections.singletonMap(Resource.Type.View, viewName));
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/fb86fb3b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ViewSubResourceService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ViewSubResourceService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ViewSubResourceService.java
deleted file mode 100644
index 76d28fe..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ViewSubResourceService.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/**
- * 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.util.HashMap;
-import java.util.Map;
-
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
-
-import org.apache.ambari.server.api.resources.ResourceInstance;
-import org.apache.ambari.server.controller.spi.Resource;
-import org.apache.ambari.server.orm.entities.ViewEntity;
-import org.apache.ambari.server.orm.entities.ViewInstanceEntity;
-import org.apache.ambari.view.ViewResourceHandler;
-
-/**
- * View sub-resource service.
- */
-public class ViewSubResourceService extends BaseService implements ViewResourceHandler {
- /**
- * The type of the sub-resource.
- */
- private final Resource.Type type;
-
- /**
- * The associated view name.
- */
- private final String viewName;
-
- /**
- * The view version.
- */
- private final String version;
-
- /**
- * The associated view instance name.
- */
- private final String instanceName;
-
-
- // ----- Constructors ------------------------------------------------------
-
- /**
- * Construct a view sub-resource service.
- */
- public ViewSubResourceService(Resource.Type type, ViewInstanceEntity viewInstanceDefinition) {
- ViewEntity viewEntity = viewInstanceDefinition.getViewEntity();
-
- this.type = type;
- this.viewName = viewEntity.getCommonName();
- this.version = viewEntity.getVersion();
- this.instanceName = viewInstanceDefinition.getName();
- }
-
-
- // ----- ViewResourceHandler -----------------------------------------------
-
- @Override
- public Response handleRequest(HttpHeaders headers, UriInfo ui,
- RequestType requestType, MediaType mediaType,
- String resourceId) {
- return handleRequest(headers, null, ui, getRequestType(requestType),
- getMediaType(mediaType), createResource(resourceId));
- }
-
- @Override
- public Response handleRequest(HttpHeaders headers, UriInfo ui, String resourceId) {
- return handleRequest(headers, null, ui, Request.Type.GET,
- createResource(resourceId));
- }
-
-
- // ----- helper methods ----------------------------------------------------
-
- // create a resource with the given id
- protected ResourceInstance createResource(String resourceId) {
- Map<Resource.Type,String> mapIds = new HashMap<Resource.Type,String>();
-
- mapIds.put(Resource.Type.View, viewName);
- mapIds.put(Resource.Type.ViewVersion, version);
- mapIds.put(Resource.Type.ViewInstance, instanceName);
-
- if (resourceId != null) {
- mapIds.put(type, resourceId);
- }
- return super.createResource(type, mapIds);
- }
-
- // get the internal request type from the view API request type
- private Request.Type getRequestType(RequestType type) {
- switch (type) {
- case GET:
- return Request.Type.GET;
- case POST:
- return Request.Type.POST;
- case PUT:
- return Request.Type.PUT;
- case DELETE:
- return Request.Type.DELETE;
- case QUERY_POST:
- return Request.Type.QUERY_POST;
- }
- throw new IllegalArgumentException("Unknown resource type " + type);
- }
-
- // get the JAX-RS media type from the view media type
- private javax.ws.rs.core.MediaType getMediaType(MediaType type) {
- switch (type) {
- case TEXT_PLAIN:
- return javax.ws.rs.core.MediaType.TEXT_PLAIN_TYPE;
- case APPLICATION_JSON:
- return javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE;
- }
- throw new IllegalArgumentException("Unknown media type " + type);
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/fb86fb3b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ViewVersionService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ViewVersionService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ViewVersionService.java
deleted file mode 100644
index 3554da1..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ViewVersionService.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/**
- * 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.util.HashMap;
-import java.util.Map;
-
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-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.HttpHeaders;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
-
-import org.apache.ambari.server.api.resources.ResourceInstance;
-import org.apache.ambari.server.controller.spi.Resource;
-
-
-/**
- * Service responsible for view version resource requests.
- */
-public class ViewVersionService extends BaseService {
-
- /**
- * Parent view name.
- */
- private final String viewName;
-
-
- // ----- Constructors ------------------------------------------------------
-
- /**
- * Construct a view version service.
- *
- * @param viewName the view name
- */
- public ViewVersionService(String viewName) {
- this.viewName = viewName;
- }
-
-
- // ----- ViewVersionService ------------------------------------------------
-
- /**
- * Handles: GET /versions/{version}
- * Get a specific view version.
- *
- * @param headers http headers
- * @param ui uri info
- * @param version version id
- *
- * @return view instance representation
- */
- @GET
- @Path("{version}")
- @Produces("text/plain")
- public Response getVersions(String body, @Context HttpHeaders headers, @Context UriInfo ui,
- @PathParam("version") String version) {
-
- return handleRequest(headers, body, ui, Request.Type.GET, createResource(viewName, version));
- }
-
- /**
- * Handles: GET /versions
- * Get all views versions.
- *
- * @param headers http headers
- * @param ui uri info
- *
- * @return view collection resource representation
- */
- @GET
- @Produces("text/plain")
- public Response getVersions(String body, @Context HttpHeaders headers, @Context UriInfo ui) {
-
- return handleRequest(headers, body, ui, Request.Type.GET, createResource(viewName, null));
- }
-
- /**
- * Handles: POST /versions/{version}
- * Create a specific view version.
- *
- * @param headers http headers
- * @param ui uri info
- * @param version the version
- *
- * @return information regarding the created view
- */
- @POST
- @Path("{version}")
- @Produces("text/plain")
- public Response createVersions(String body, @Context HttpHeaders headers, @Context UriInfo ui,
- @PathParam("version") String version) {
-
- return handleRequest(headers, body, ui, Request.Type.POST, createResource(viewName, version));
- }
-
- /**
- * Handles: PUT /versions/{version}
- * Update a specific view version.
- *
- * @param headers http headers
- * @param ui uri info
- * @param version the version
- *
- * @return information regarding the updated view
- */
- @PUT
- @Path("{version}")
- @Produces("text/plain")
- public Response updateVersions(String body, @Context HttpHeaders headers, @Context UriInfo ui,
- @PathParam("version") String version) {
-
- return handleRequest(headers, body, ui, Request.Type.PUT, createResource(viewName, version));
- }
-
- /**
- * Handles: DELETE /versions/{version}
- * Delete a specific view version.
- *
- * @param headers http headers
- * @param ui uri info
- * @param version version id
- *
- * @return information regarding the deleted view version
- */
- @DELETE
- @Path("{version}")
- @Produces("text/plain")
- public Response deleteVersions(@Context HttpHeaders headers, @Context UriInfo ui,
- @PathParam("version") String version) {
-
- return handleRequest(headers, null, ui, Request.Type.DELETE, createResource(viewName, version));
- }
-
- /**
- * Get the instances sub-resource
- *
- * @param version the version
- *
- * @return the instance service
- */
- @Path("{version}/instances")
- public ViewInstanceService getInstanceHandler(@PathParam("version") String version) {
-
- return new ViewInstanceService(viewName, version);
- }
-
- /**
- * Get the permissions sub-resource
- *
- * @param version the version
- *
- * @return the permission service
- */
- @Path("{version}/permissions")
- public ViewPermissionService getPermissionHandler(@PathParam("version") String version) {
-
- return new ViewPermissionService(viewName, version);
- }
-
-
- // ----- helper methods ----------------------------------------------------
-
- /**
- * Create a view resource.
- *
- * @param viewName view name
- *
- * @return a view resource instance
- */
- private ResourceInstance createResource(String viewName, String version) {
- Map<Resource.Type,String> mapIds = new HashMap<Resource.Type, String>();
- mapIds.put(Resource.Type.View, viewName);
- mapIds.put(Resource.Type.ViewVersion, version);
- return createResource(Resource.Type.ViewVersion, mapIds);
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/fb86fb3b/ambari-server/src/main/java/org/apache/ambari/server/api/services/groups/GroupPrivilegeService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/groups/GroupPrivilegeService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/groups/GroupPrivilegeService.java
new file mode 100644
index 0000000..8a23885
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/groups/GroupPrivilegeService.java
@@ -0,0 +1,113 @@
+/*
+ * 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.groups;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.ws.rs.GET;
+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.HttpHeaders;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.ambari.server.api.resources.ResourceInstance;
+import org.apache.ambari.server.api.services.BaseService;
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.controller.GroupPrivilegeResponse;
+import org.apache.ambari.server.controller.PrivilegeResponse;
+import org.apache.ambari.server.controller.spi.Resource;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+
+/**
+ * Service responsible for group privilege resource requests.
+ */
+@Path("/groups/{groupName}/privileges")
+@Api(value = "Groups", description = "Endpoint for group specific operations")
+public class GroupPrivilegeService extends BaseService {
+
+ /**
+ * Handles: GET /groups/{groupName}/privileges
+ * Get all group privileges.
+ * @param headers
+ * @param ui
+ * @param groupName
+ * @return
+ */
+ @GET
+ @Produces("text/plain")
+ @ApiOperation(value = "Get all privileges", notes = "Returns all privileges for group.", response = GroupPrivilegeResponse.class, responseContainer = "List")
+ @ApiImplicitParams({
+ @ApiImplicitParam(name = "fields", value = "Filter user privileges", defaultValue = "PrivilegeInfo/*", dataType = "string", paramType = "query"),
+ @ApiImplicitParam(name = "sortBy", value = "Sort user privileges (asc | desc)", defaultValue = "PrivilegeInfo/user_name.asc", dataType = "string", paramType = "query"),
+ @ApiImplicitParam(name = "page_size", value = "The number of resources to be returned for the paged response.", defaultValue = "10", dataType = "integer", paramType = "query"),
+ @ApiImplicitParam(name = "from", value = "The starting page resource (inclusive). Valid values are :offset | \"start\"", defaultValue = "0", dataType = "string", paramType = "query"),
+ @ApiImplicitParam(name = "to", value = "The ending page resource (inclusive). Valid values are :offset | \"end\"", dataType = "string", paramType = "query")
+ })
+
+ public Response getPrivileges(@Context HttpHeaders headers, @Context UriInfo ui,
+ @ApiParam(value = "group name", required = true) @PathParam("groupName") String groupName) {
+ return handleRequest(headers, null, ui, Request.Type.GET, createPrivilegeResource(groupName, null));
+ }
+
+
+ /**
+ * Handles: GET /groups/{groupName}/privileges{privilegeID}
+ * Get a specific privilege for a group.
+ *
+ * @param headers http headers
+ * @param ui uri info
+ * @param groupName group name
+ * @param privilegeId privilege id
+ * @return privilege instance representation
+ */
+ @GET
+ @Path("{privilegeId}")
+ @Produces("text/plain")
+ @ApiOperation(value = "Get group privilege", notes = "Returns group privilege details.", response = GroupPrivilegeResponse.class)
+ @ApiImplicitParams({
+ @ApiImplicitParam(name = "fields", value = "Filter group privilege details", defaultValue = "PrivilegeInfo/*", dataType = "string", paramType = "query")
+ })
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "Successful operation", response = PrivilegeResponse.class)}
+ )
+ public Response getPrivilege(@Context HttpHeaders headers, @Context UriInfo ui, @ApiParam(value = "user name", required = true) @PathParam ("userName") String groupName,
+ @ApiParam(value = "privilege id", required = true) @PathParam("privilegeId") String privilegeId) {
+ return handleRequest(headers, null, ui, Request.Type.GET, createPrivilegeResource(groupName, privilegeId));
+ }
+
+
+
+ protected ResourceInstance createPrivilegeResource(String groupName, String privilegeId) {
+ final Map<Resource.Type, String> mapIds = new HashMap<Resource.Type, String>();
+ mapIds.put(Resource.Type.Group, groupName);
+ mapIds.put(Resource.Type.GroupPrivilege, privilegeId);
+ return createResource(Resource.Type.GroupPrivilege, mapIds);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/fb86fb3b/ambari-server/src/main/java/org/apache/ambari/server/api/services/groups/GroupService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/groups/GroupService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/groups/GroupService.java
new file mode 100644
index 0000000..ad9db28
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/groups/GroupService.java
@@ -0,0 +1,177 @@
+/**
+ * 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.groups;
+
+import java.util.Collections;
+
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+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.HttpHeaders;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.ambari.server.api.resources.ResourceInstance;
+import org.apache.ambari.server.api.services.BaseService;
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.controller.GroupResponse;
+import org.apache.ambari.server.controller.spi.Resource;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+
+/**
+ * Service responsible for user groups requests.
+ */
+@Path("/groups/")
+@Api(value = "Groups", description = "Endpoint for group specific operations")
+public class GroupService extends BaseService {
+ /**
+ * Gets all groups.
+ * Handles: GET /groups requests.
+ *
+ * @param headers http headers
+ * @param ui uri info
+ */
+ @GET
+ @Produces("text/plain")
+ @ApiOperation(value = "Get all groups", notes = "Returns details of all groups.", response = GroupResponse.class, responseContainer = "List")
+ @ApiImplicitParams({
+ @ApiImplicitParam(name = "fields", value = "Filter group details", defaultValue = "Groups/*", dataType = "string", paramType = "query"),
+ @ApiImplicitParam(name = "sortBy", value = "Sort groups (asc | desc)", defaultValue = "Groups/group_name.asc", dataType = "string", paramType = "query"),
+ @ApiImplicitParam(name = "page_size", value = "The number of resources to be returned for the paged response.", defaultValue = "10", dataType = "integer", paramType = "query"),
+ @ApiImplicitParam(name = "from", value = "The starting page resource (inclusive). Valid values are :offset | \"start\"", defaultValue = "0", dataType = "string", paramType = "query"),
+ @ApiImplicitParam(name = "to", value = "The ending page resource (inclusive). Valid values are :offset | \"end\"", dataType = "string", paramType = "query")
+ })
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "Successful retrieval of all group entries", response = GroupResponse.class, responseContainer = "List")}
+ )
+ public Response getGroups(@Context HttpHeaders headers, @Context UriInfo ui) {
+ return handleRequest(headers, null, ui, Request.Type.GET, createGroupResource(null));
+ }
+
+ /**
+ * Gets a single group.
+ * Handles: GET /groups/{groupName} requests.
+ *
+ * @param headers http headers
+ * @param ui uri info
+ * @param groupName the group name
+ * @return information regarding the specified group
+ */
+ @GET
+ @Path("{groupName}")
+ @Produces("text/plain")
+ @ApiOperation(value = "Get group", notes = "Returns group details.", response = GroupResponse.class)
+ @ApiImplicitParams({
+ @ApiImplicitParam(name = "fields", value = "Filter group details", defaultValue = "Groups", dataType = "string", paramType = "query")
+ })
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "Successful retrieval of group resource", response = GroupResponse.class)}
+ )
+ public Response getGroup(@Context HttpHeaders headers, @Context UriInfo ui,
+ @ApiParam(value = "group name", required = true) @PathParam("groupName") String groupName) {
+ return handleRequest(headers, null, ui, Request.Type.GET, createGroupResource(groupName));
+ }
+
+ /**
+ * Creates a group.
+ * Handles: POST /groups requests.
+ *
+ * @param headers http headers
+ * @param ui uri info
+ * @return information regarding the created group
+ */
+ @POST
+ @Produces("text/plain")
+ @ApiOperation(value = "Create new group", notes = "Creates group resource.")
+ @ApiImplicitParams({
+ @ApiImplicitParam(name = "body", value = "input parameters in json form", required = true, dataType = "org.apache.ambari.server.controller.GroupRequest", paramType = "body")
+ })
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "successful operation"),
+ @ApiResponse(code = 500, message = "Server Error")}
+ )
+ public Response createGroup(String body, @Context HttpHeaders headers, @Context UriInfo ui) {
+ return handleRequest(headers, body, ui, Request.Type.POST, createGroupResource(null));
+ }
+
+ /**
+ * Creates a group.
+ * Handles: POST /groups/{groupName} requests.
+ *
+ * @param headers http headers
+ * @param ui uri info
+ * @param groupName the group name
+ * @return information regarding the created group
+ *
+ * @deprecated Use requests to /groups instead.
+ */
+ @POST
+ @Deprecated
+ @Path("{groupName}")
+ @Produces("text/plain")
+ public Response createGroup(String body, @Context HttpHeaders headers, @Context UriInfo ui,
+ @PathParam("groupName") String groupName) {
+ return handleRequest(headers, body, ui, Request.Type.POST, createGroupResource(groupName));
+ }
+
+ /**
+ * Deletes a group.
+ * Handles: DELETE /groups/{groupName} requests.
+ *
+ * @param headers http headers
+ * @param ui uri info
+ * @param groupName the group name
+ * @return information regarding the deleted group
+ */
+ @DELETE
+ @Path("{groupName}")
+ @Produces("text/plain")
+ @ApiOperation(value = "Delete group", notes = "Delete group resource.")
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "Successful operation"),
+ @ApiResponse(code = 500, message = "Server Error")}
+ )
+ public Response deleteGroup(@Context HttpHeaders headers, @Context UriInfo ui,
+ @ApiParam(value = "group name", required = true) @PathParam("groupName") String groupName) {
+ return handleRequest(headers, null, ui, Request.Type.DELETE, createGroupResource(groupName));
+ }
+
+
+ /**
+ * Create a group resource instance.
+ *
+ * @param groupName group name
+ *
+ * @return a group resource instance
+ */
+ private ResourceInstance createGroupResource(String groupName) {
+ return createResource(Resource.Type.Group,
+ Collections.singletonMap(Resource.Type.Group, groupName));
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/fb86fb3b/ambari-server/src/main/java/org/apache/ambari/server/api/services/groups/MemberService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/groups/MemberService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/groups/MemberService.java
new file mode 100644
index 0000000..ec02511
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/groups/MemberService.java
@@ -0,0 +1,200 @@
+/**
+ * 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.groups;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+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.HttpHeaders;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.ambari.server.api.resources.ResourceInstance;
+import org.apache.ambari.server.api.services.BaseService;
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.controller.MemberResponse;
+import org.apache.ambari.server.controller.spi.Resource;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+
+/**
+ * Service responsible for user membership requests.
+ */
+@Path("/groups/{groupName}/members")
+@Api(value = "Groups", description = "Endpoint for group specific operations")
+public class MemberService extends BaseService {
+ /**
+ * Creates new members.
+ * Handles: POST /groups/{groupname}/members requests.
+ *
+ * @param headers http headers
+ * @param ui uri info
+ * @param groupName group name
+ * @return information regarding the created member
+ */
+ @POST
+ @Produces("text/plain")
+ public Response createMember(String body, @Context HttpHeaders headers, @Context UriInfo ui, @PathParam("groupName") String groupName) {
+ return handleRequest(headers, body, ui, Request.Type.POST, createMemberResource(groupName, null));
+ }
+
+ /**
+ * Creates a new member.
+ * Handles: POST /groups/{groupname}/members/{username} requests.
+ *
+ * @param headers http headers
+ * @param ui uri info
+ * @param groupName group name
+ * @param userName the user name
+ * @return information regarding the created member
+ */
+ @POST
+ @Path("{userName}")
+ @Produces("text/plain")
+ public Response createMember(String body, @Context HttpHeaders headers, @Context UriInfo ui, @PathParam("groupName") String groupName,
+ @PathParam("userName") String userName) {
+ return handleRequest(headers, body, ui, Request.Type.POST, createMemberResource(groupName, userName));
+ }
+
+ /**
+ * Deletes a member.
+ * Handles: DELETE /groups/{groupname}/members/{username} requests.
+ *
+ * @param headers http headers
+ * @param ui uri info
+ * @param groupName group name
+ * @param userName the user name
+ * @return information regarding the deleted group
+ */
+ @DELETE
+ @Path("{userName}")
+ @Produces("text/plain")
+ @ApiOperation(value = "Delete group member", notes = "Delete member resource.")
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "Successful operation"),
+ @ApiResponse(code = 500, message = "Server Error")}
+ )
+ public Response deleteMember(@Context HttpHeaders headers, @Context UriInfo ui, @ApiParam(value = "group name", required = true) @PathParam("groupName") String groupName,
+ @ApiParam(value = "user name", required = true) @PathParam("userName") String userName) {
+ return handleRequest(headers, null, ui, Request.Type.DELETE, createMemberResource(groupName, userName));
+ }
+
+ /**
+ * Gets all members.
+ * Handles: GET /groups/{groupname}/members requests.
+ *
+ * @param headers http headers
+ * @param ui uri info
+ * @param groupName group name
+ * @return information regarding all members
+ */
+ @GET
+ @Produces("text/plain")
+ @ApiOperation(value = "Get all group members", notes = "Returns details of all members.", response = MemberResponse.class, responseContainer = "List")
+ @ApiImplicitParams({
+ @ApiImplicitParam(name = "fields", value = "Filter member details", defaultValue = "MemberInfo/*", dataType = "string", paramType = "query"),
+ @ApiImplicitParam(name = "sortBy", value = "Sort members (asc | desc)", defaultValue = "MemberInfo/user_name.asc", dataType = "string", paramType = "query"),
+ @ApiImplicitParam(name = "page_size", value = "The number of resources to be returned for the paged response.", defaultValue = "10", dataType = "integer", paramType = "query"),
+ @ApiImplicitParam(name = "from", value = "The starting page resource (inclusive). Valid values are :offset | \"start\"", defaultValue = "0", dataType = "string", paramType = "query"),
+ @ApiImplicitParam(name = "to", value = "The ending page resource (inclusive). Valid values are :offset | \"end\"", dataType = "string", paramType = "query")
+ })
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "Successful operation", response = MemberResponse.class, responseContainer = "List")}
+ )
+ public Response getMembers(@Context HttpHeaders headers, @Context UriInfo ui, @ApiParam(value = "group name", required = true) @PathParam("groupName") String groupName) {
+ return handleRequest(headers, null, ui, Request.Type.GET, createMemberResource(groupName, null));
+ }
+
+ /**
+ * Gets member.
+ * Handles: GET /groups/{groupname}/members/{username} requests.
+ *
+ * @param headers http headers
+ * @param ui uri info
+ * @param groupName group name
+ * @param userName the user name
+ * @return information regarding the specific member
+ */
+ @GET
+ @Path("{userName}")
+ @Produces("text/plain")
+ @ApiOperation(value = "Get group member", notes = "Returns member details.", response = MemberResponse.class)
+ @ApiImplicitParams({
+ @ApiImplicitParam(name = "fields", value = "Filter member details", defaultValue = "MemberInfo", dataType = "string", paramType = "query")
+ })
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "Successful operation", response = MemberResponse.class)}
+ )
+ public Response getMember(@Context HttpHeaders headers, @Context UriInfo ui, @ApiParam(value = "group name", required = true) @PathParam("groupName") String groupName,
+ @ApiParam(value = "user name", required = true) @PathParam("userName") String userName) {
+ return handleRequest(headers, null, ui, Request.Type.GET, createMemberResource(groupName, userName));
+ }
+
+ /**
+ * Updates all members.
+ * Handles: PUT /groups/{groupname}/members requests.
+ *
+ * @param headers http headers
+ * @param ui uri info
+ * @param groupName group name
+ * @return status of the request
+ */
+ @PUT
+ @Produces("text/plain")
+ @ApiOperation(value = "Update group members", notes = "Updates group member resources.", responseContainer = "List")
+ @ApiImplicitParams({
+ @ApiImplicitParam(name = "body", value = "input parameters in json form", required = true, dataType = "org.apache.ambari.server.controller.MemberRequest", paramType = "body")
+ })
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "Successful operation"),
+ @ApiResponse(code = 500, message = "Server Error")}
+ )
+ public Response updateMembers(String body, @Context HttpHeaders headers, @Context UriInfo ui, @ApiParam(value = "group name", required = true)
+ @PathParam("groupName") String groupName) {
+ return handleRequest(headers, body, ui, Request.Type.PUT, createMemberResource(groupName, null));
+ }
+
+ /**
+ * Create a member resource instance.
+ *
+ * @param groupName group name
+ * @param userName user name
+ *
+ * @return a member resource instance
+ */
+ private ResourceInstance createMemberResource(String groupName, String userName) {
+ final Map<Resource.Type, String> mapIds = new HashMap<Resource.Type, String>();
+ mapIds.put(Resource.Type.Group, groupName);
+ mapIds.put(Resource.Type.Member, userName);
+ return createResource(Resource.Type.Member, mapIds);
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/fb86fb3b/ambari-server/src/main/java/org/apache/ambari/server/api/services/users/ActiveWidgetLayoutService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/users/ActiveWidgetLayoutService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/users/ActiveWidgetLayoutService.java
new file mode 100644
index 0000000..30714d4
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/users/ActiveWidgetLayoutService.java
@@ -0,0 +1,111 @@
+/**
+ * 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.users;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.ws.rs.GET;
+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.HttpHeaders;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.ambari.server.api.resources.ResourceInstance;
+import org.apache.ambari.server.api.services.BaseService;
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.controller.ActiveWidgetLayoutResponse;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.commons.lang.StringUtils;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+
+/**
+ * WidgetLayout Service
+ */
+@Path("/users/{userName}/activeWidgetLayouts")
+@Api(value = "Users", description = "Endpoint for User specific operations")
+public class ActiveWidgetLayoutService extends BaseService {
+
+ /**
+ * Handles URL: /users/{userName}/activeWidgetLayouts
+ * Get all instances for a view.
+ *
+ * @param headers http headers
+ * @param ui uri info
+ * @param userName user name
+ *
+ * @return instance collection resource representation
+ */
+ @GET
+ @Produces("text/plain")
+ @ApiOperation(value = "Get user widget layouts", notes = "Returns all active widget layouts for user.", response = ActiveWidgetLayoutResponse.class, responseContainer = "List")
+ @ApiImplicitParams({
+ @ApiImplicitParam(name = "fields", value = "Filter user layout details", defaultValue = "WidgetLayoutInfo/*", dataType = "string", paramType = "query"),
+ @ApiImplicitParam(name = "sortBy", value = "Sort layouts (asc | desc)", defaultValue = "WidgetLayoutInfo/user_name.asc", dataType = "string", paramType = "query"),
+ @ApiImplicitParam(name = "page_size", value = "The number of resources to be returned for the paged response.", defaultValue = "10", dataType = "integer", paramType = "query"),
+ @ApiImplicitParam(name = "from", value = "The starting page resource (inclusive). Valid values are :offset | \"start\"", defaultValue = "0", dataType = "string", paramType = "query"),
+ @ApiImplicitParam(name = "to", value = "The ending page resource (inclusive). Valid values are :offset | \"end\"", dataType = "string", paramType = "query")
+ })
+ public Response getServices(String body, @Context HttpHeaders headers, @Context UriInfo ui, @ApiParam(value = "user name", required = true)
+ @PathParam("userName") String userName) {
+
+ return handleRequest(headers, body, ui, Request.Type.GET, createResource(userName));
+ }
+
+ /**
+ *
+ * @param body body
+ * @param headers http headers
+ * @param ui uri info
+ * @param userName user name
+ * @return
+ */
+ @PUT
+ @Produces("text/plain")
+ @ApiOperation(value = "Update user widget layouts", notes = "Updates user widget layout.")
+ @ApiImplicitParams({
+ @ApiImplicitParam(name = "body", value = "input parameters in json form", required = true, dataType = "org.apache.ambari.server.controller.ActiveWidgetLayoutRequest", paramType = "body")
+ })
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "Successful operation"),
+ @ApiResponse(code = 500, message = "Server Error")}
+ )
+ public Response updateServices(String body, @Context HttpHeaders headers, @Context UriInfo ui, @ApiParam(value = "user name", required = true)
+ @PathParam("userName") String userName) {
+
+ return handleRequest(headers, body, ui, Request.Type.PUT, createResource(userName));
+ }
+
+ private ResourceInstance createResource(String userName) {
+ Map<Resource.Type,String> mapIds = new HashMap<Resource.Type, String>();
+ mapIds.put(Resource.Type.User, StringUtils.lowerCase(userName));
+ return createResource(Resource.Type.ActiveWidgetLayout, mapIds);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/fb86fb3b/ambari-server/src/main/java/org/apache/ambari/server/api/services/users/UserAuthorizationService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/users/UserAuthorizationService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/users/UserAuthorizationService.java
new file mode 100644
index 0000000..e6fda46
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/users/UserAuthorizationService.java
@@ -0,0 +1,120 @@
+/*
+ * 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.users;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.ws.rs.GET;
+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.HttpHeaders;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.ambari.server.api.resources.ResourceInstance;
+import org.apache.ambari.server.api.services.BaseService;
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.controller.UserAuthorizationResponse;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.commons.lang.StringUtils;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+
+/**
+ * UserAuthorizationService is a read-only service responsible for user authorization resource requests.
+ * <p/>
+ * The result sets returned by this service represent the set of authorizations assigned to a given user.
+ * Authorizations are tied to a resource, so a user may have the multiple authorization entries for the
+ * same authorization id (for example VIEW.USE), however each will represnet a different view instance.
+ */
+@Path("/users/{userName}/authorizations")
+@Api(value = "Users", description = "Endpoint for user specific operations")
+public class UserAuthorizationService extends BaseService {
+
+ /**
+ * Handles: GET /users/{user_name}/authorizations
+ * Get all authorizations for the relative user.
+ *
+ * @param headers http headers
+ * @param ui uri info
+ * @param userName user name
+ * @return authorizations collection resource representation
+ */
+ @GET
+ @Produces("text/plain")
+ @ApiOperation(value = "Get all authorizations", notes = "Returns all authorization for user.", response = UserAuthorizationResponse.class, responseContainer = "List")
+ @ApiImplicitParams({
+ @ApiImplicitParam(name = "fields", value = "Filter user authorization details", defaultValue = "AuthorizationInfo/*", dataType = "string", paramType = "query"),
+ @ApiImplicitParam(name = "sortBy", value = "Sort user authorizations (asc | desc)", defaultValue = "AuthorizationInfo/user_name.asc", dataType = "string", paramType = "query"),
+ @ApiImplicitParam(name = "page_size", value = "The number of resources to be returned for the paged response.", defaultValue = "10", dataType = "integer", paramType = "query"),
+ @ApiImplicitParam(name = "from", value = "The starting page resource (inclusive). Valid values are :offset | \"start\"", defaultValue = "0", dataType = "string", paramType = "query"),
+ @ApiImplicitParam(name = "to", value = "The ending page resource (inclusive). Valid values are :offset | \"end\"", dataType = "string", paramType = "query")
+ })
+ public Response getAuthorizations(@Context HttpHeaders headers, @Context UriInfo ui, @ApiParam(value = "user name", required = true)
+ @PathParam ("userName") String userName) {
+ return handleRequest(headers, null, ui, Request.Type.GET, createAuthorizationResource(userName,null));
+ }
+
+ /**
+ * Handles: GET /users/{userName}/authorizations/{authorization_id}
+ * Get a specific authorization.
+ *
+ * @param headers http headers
+ * @param ui uri info
+ * @param userName user name
+ * @param authorizationId authorization ID
+ * @return authorization instance representation
+ */
+ @GET
+ @Path("{authorization_id}")
+ @Produces("text/plain")
+ @ApiOperation(value = "Get user authorization", notes = "Returns user authorization details.", response = UserAuthorizationResponse.class)
+ @ApiImplicitParams({
+ @ApiImplicitParam(name = "fields", value = "Filter user authorization details", defaultValue = "AuthorizationInfo/*", dataType = "string", paramType = "query")
+ })
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "Successful operation", response = UserAuthorizationResponse.class)}
+ )
+ public Response getAuthorization(@Context HttpHeaders headers, @Context UriInfo ui, @ApiParam(value = "user name", required = true)
+ @PathParam ("userName") String userName, @ApiParam(value = "Authorization Id", required = true) @PathParam("authorization_id") String authorizationId) {
+ return handleRequest(headers, null, ui, Request.Type.GET, createAuthorizationResource(userName, authorizationId));
+ }
+
+ /**
+ * Create an authorization resource.
+ * @param userName user name
+ * @param authorizationId authorization id
+ * @return an authorization resource instance
+ */
+ protected ResourceInstance createAuthorizationResource(String userName, String authorizationId) {
+ Map<Resource.Type, String> mapIds = new HashMap<Resource.Type, String>();
+ mapIds.put(Resource.Type.User, StringUtils.lowerCase(userName));
+ mapIds.put(Resource.Type.UserAuthorization, authorizationId);
+ return createResource(Resource.Type.UserAuthorization, mapIds);
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/fb86fb3b/ambari-server/src/main/java/org/apache/ambari/server/api/services/users/UserPrivilegeService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/users/UserPrivilegeService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/users/UserPrivilegeService.java
new file mode 100644
index 0000000..d6b4b29
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/users/UserPrivilegeService.java
@@ -0,0 +1,113 @@
+/**
+ * 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 privileges and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.api.services.users;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.ws.rs.GET;
+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.HttpHeaders;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.ambari.server.api.resources.ResourceInstance;
+import org.apache.ambari.server.api.services.BaseService;
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.controller.UserPrivilegeResponse;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.commons.lang.StringUtils;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+
+/**
+ * Service responsible for user privilege resource requests.
+ */
+@Path("/users/{userName}/privileges")
+@Api(value = "Users", description = "Endpoint for user specific operations")
+public class UserPrivilegeService extends BaseService {
+
+
+ /**
+ * Handles: GET /users/{userName}/privileges
+ * Get all privileges.
+ * @param headers
+ * @param ui
+ * @param userName
+ * @return
+ */
+ @GET
+ @Produces("text/plain")
+ @ApiOperation(value = "Get all privileges", notes = "Returns all privileges for user.", response = UserPrivilegeResponse.class, responseContainer = "List")
+ @ApiImplicitParams({
+ @ApiImplicitParam(name = "fields", value = "Filter user privileges", defaultValue = "PrivilegeInfo/*", dataType = "string", paramType = "query"),
+ @ApiImplicitParam(name = "sortBy", value = "Sort user privileges (asc | desc)", defaultValue = "PrivilegeInfo/user_name.asc", dataType = "string", paramType = "query"),
+ @ApiImplicitParam(name = "page_size", value = "The number of resources to be returned for the paged response.", defaultValue = "10", dataType = "integer", paramType = "query"),
+ @ApiImplicitParam(name = "from", value = "The starting page resource (inclusive). Valid values are :offset | \"start\"", defaultValue = "0", dataType = "string", paramType = "query"),
+ @ApiImplicitParam(name = "to", value = "The ending page resource (inclusive). Valid values are :offset | \"end\"", dataType = "string", paramType = "query")
+ })
+
+ public Response getPrivileges(@Context HttpHeaders headers, @Context UriInfo ui,
+ @ApiParam(value = "user name", required = true, defaultValue = "admin") @PathParam("userName") String userName) {
+ return handleRequest(headers, null, ui, Request.Type.GET, createPrivilegeResource(userName, null));
+ }
+
+ /**
+ * Handles: GET /users/{userName}/privileges/{privilegeID}
+ * Get a specific privilege.
+ *
+ * @param headers http headers
+ * @param ui uri info
+ * @param userName user name
+ * @param privilegeId privilege id
+ *
+ * @return privilege instance representation
+ */
+ @GET
+ @Path("{privilegeId}")
+ @Produces("text/plain")
+ @ApiOperation(value = "Get user privilege", notes = "Returns user privilege details.", response = UserPrivilegeResponse.class)
+ @ApiImplicitParams({
+ @ApiImplicitParam(name = "fields", value = "Filter user privilege details", defaultValue = "PrivilegeInfo/*", dataType = "string", paramType = "query")
+ })
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "Successful operation", response = UserPrivilegeResponse.class)}
+ )
+ public Response getPrivilege(@Context HttpHeaders headers, @Context UriInfo ui, @ApiParam(value = "user name", required = true) @PathParam ("userName") String userName,
+ @ApiParam(value = "privilege id", required = true) @PathParam("privilegeId") String privilegeId) {
+ return handleRequest(headers, null, ui, Request.Type.GET, createPrivilegeResource(userName, privilegeId));
+ }
+
+
+ protected ResourceInstance createPrivilegeResource(String userName, String privilegeId) {
+ final Map<Resource.Type, String> mapIds = new HashMap<Resource.Type, String>();
+ mapIds.put(Resource.Type.User, StringUtils.lowerCase(userName));
+ mapIds.put(Resource.Type.UserPrivilege, privilegeId);
+ return createResource(Resource.Type.UserPrivilege, mapIds);
+ }
+}
\ No newline at end of file