Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,12 @@
import org.apache.ambari.server.controller.internal.ResourceImpl;
import org.apache.ambari.server.controller.spi.Resource;
import org.apache.ambari.server.controller.spi.Resource.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Resource Definition for Mpack Resource types.
*/
public class MpackResourceDefinition extends BaseResourceDefinition {

private final static Logger LOG =
LoggerFactory.getLogger(MpackResourceDefinition.class);

public MpackResourceDefinition(Type resourceType) {
super(Resource.Type.Mpack);
}
Expand All @@ -61,6 +56,7 @@ public String getSingularName() {
public Set<SubResourceDefinition> getSubResourceDefinitions() {
Set<SubResourceDefinition> setChildren = new HashSet<>();
setChildren.add(new SubResourceDefinition(Resource.Type.StackVersion, null, false));
setChildren.add(new SubResourceDefinition(Resource.Type.OperatingSystem, null, true));
return setChildren;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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.resources;

import java.util.Collections;
import java.util.Set;

import org.apache.ambari.annotations.Experimental;
import org.apache.ambari.annotations.ExperimentalFeature;
import org.apache.ambari.server.controller.spi.Resource;
import org.apache.ambari.server.controller.spi.Resource.Type;

@Deprecated
@Experimental(feature = ExperimentalFeature.REPO_VERSION_REMOVAL)
public class OperatingSystemReadOnlyResourceDefinition extends BaseResourceDefinition {

public OperatingSystemReadOnlyResourceDefinition(Type resourceType) {
super(resourceType);
}

public OperatingSystemReadOnlyResourceDefinition() {
super(Resource.Type.OperatingSystemReadOnly);
}

@Override
public String getPluralName() {
return "operating_systems";
}

@Override
public String getSingularName() {
return "operating_system";
}

@Override
public Set<SubResourceDefinition> getSubResourceDefinitions() {
return Collections.singleton(new SubResourceDefinition(Resource.Type.Repository));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

package org.apache.ambari.server.api.resources;

import java.util.Collections;
import java.util.Set;

import org.apache.ambari.server.controller.spi.Resource;
import org.apache.ambari.server.controller.spi.Resource.Type;

Expand All @@ -43,10 +40,4 @@ public String getPluralName() {
public String getSingularName() {
return "operating_system";
}

@Override
public Set<SubResourceDefinition> getSubResourceDefinitions() {
return Collections.singleton(new SubResourceDefinition(Resource.Type.Repository));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public String getSingularName() {

@Override
public Set<SubResourceDefinition> getSubResourceDefinitions() {
return Collections.singleton(new SubResourceDefinition(Resource.Type.OperatingSystem));
return Collections.singleton(new SubResourceDefinition(Resource.Type.OperatingSystemReadOnly));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ public static ResourceDefinition getResourceDefinition(Resource.Type type, Map<R
resourceDefinition = new OperatingSystemResourceDefinition();
break;

case OperatingSystemReadOnly:
resourceDefinition = new OperatingSystemReadOnlyResourceDefinition();
break;

case Repository:
resourceDefinition = new RepositoryResourceDefinition();
break;
Expand Down Expand Up @@ -418,7 +422,7 @@ public static ResourceDefinition getResourceDefinition(Resource.Type type, Map<R
case CompatibleRepositoryVersion:
resourceDefinition = new SimpleResourceDefinition(Resource.Type.CompatibleRepositoryVersion,
"compatible_repository_version", "compatible_repository_versions",
Resource.Type.OperatingSystem);
Resource.Type.OperatingSystemReadOnly);
break;

case HostStackVersion:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Set<SubResourceDefinition> getSubResourceDefinitions() {

Set<SubResourceDefinition> children = new HashSet<>();

children.add(new SubResourceDefinition(Resource.Type.OperatingSystem));
children.add(new SubResourceDefinition(Resource.Type.OperatingSystemReadOnly));
children.add(new SubResourceDefinition(Resource.Type.StackService));
children.add(new SubResourceDefinition(Resource.Type.StackLevelConfiguration));
children.add(new SubResourceDefinition(Resource.Type.RepositoryVersion));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public String getSingularName() {

@Override
public Set<SubResourceDefinition> getSubResourceDefinitions() {
return Collections.singleton(new SubResourceDefinition(Type.OperatingSystem));
return Collections.singleton(new SubResourceDefinition(Type.OperatingSystemReadOnly));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ public Response getRepositoryVersion(@Context HttpHeaders headers,
* @return operating systems service
*/
@Path("{repositoryVersionId}/operating_systems")
public OperatingSystemService getOperatingSystemsHandler(@PathParam("repositoryVersionId") String repositoryVersionId) {
public OperatingSystemReadOnlyService getOperatingSystemsHandler(@PathParam("repositoryVersionId") String repositoryVersionId) {
Map<Resource.Type, String> mapIds = new HashMap<>();
mapIds.putAll(parentKeyProperties);
mapIds.put(Resource.Type.CompatibleRepositoryVersion, repositoryVersionId);

return new OperatingSystemService(mapIds);
return new OperatingSystemReadOnlyService(mapIds);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
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;

Expand Down Expand Up @@ -151,6 +152,19 @@ public Response getMpack(String body, @Context HttpHeaders headers, @Context Uri
createMpackResource(id));
}

/**
* Handles ANY {id}/operating_systems request
*
* @return operating system service
*/
// TODO: find a way to handle this with Swagger (refactor or custom annotation?)
@Path("{id}/operating_systems")
public OperatingSystemService getOperatingSystemsHandler(
@ApiParam @PathParam("id") String mpackId) {
return new OperatingSystemService(mpackId);
}


@DELETE
@Path("{id}")
@Produces(MediaType.TEXT_PLAIN)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* 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.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.annotations.ApiIgnore;
import org.apache.ambari.annotations.Experimental;
import org.apache.ambari.annotations.ExperimentalFeature;
import org.apache.ambari.server.api.resources.ResourceInstance;
import org.apache.ambari.server.controller.spi.Resource;

/**
* Service responsible for operating systems requests.
*/
@Deprecated
@Experimental(feature = ExperimentalFeature.REPO_VERSION_REMOVAL)
public class OperatingSystemReadOnlyService extends BaseService {

/**
* Extra properties to be inserted into created resource.
*/
private Map<Resource.Type, String> parentKeyProperties;

/**
* Constructor.
*
* @param parentKeyProperties extra properties to be inserted into created resource
*/
public OperatingSystemReadOnlyService(Map<Resource.Type, String> parentKeyProperties) {
this.parentKeyProperties = parentKeyProperties;
}

/**
* Gets all operating systems.
* Handles: GET /operating_systems requests.
*
* @param headers http headers
* @param ui uri info
*/
@GET @ApiIgnore // until documented
@Produces("text/plain")
public Response getOperatingSystems(@Context HttpHeaders headers, @Context UriInfo ui) {
return handleRequest(headers, null, ui, Request.Type.GET, createResource(null));
}

/**
* Gets a single operating system.
* Handles: GET /operating_systems/{osType} requests.
*
* @param headers http headers
* @param ui uri info
* @param osType os type
* @return information regarding the specified operating system
*/
@GET @ApiIgnore // until documented
@Path("{osType}")
@Produces("text/plain")
public Response getOperatingSystem(@Context HttpHeaders headers, @Context UriInfo ui, @PathParam("osType") String osType) {
return handleRequest(headers, null, ui, Request.Type.GET, createResource(osType));
}

/**
* Handles ANY /{osType}/repositories requests.
*
* @param osType the os type
* @return repositories service
*/
@Path("{osType}/repositories")
public RepositoryService getOperatingSystemsHandler(@PathParam("osType") String osType) {
final Map<Resource.Type, String> mapIds = new HashMap<>();
mapIds.putAll(parentKeyProperties);
mapIds.put(Resource.Type.OperatingSystemReadOnly, osType);
return new RepositoryService(mapIds);
}

/**
* Create an operating system resource instance.
*
* @param osType os type
*
* @return an operating system instance
*/
private ResourceInstance createResource(String osType) {
final Map<Resource.Type, String> mapIds = new HashMap<>();
mapIds.putAll(parentKeyProperties);
mapIds.put(Resource.Type.OperatingSystemReadOnly, osType);
return createResource(Resource.Type.OperatingSystemReadOnly, mapIds);
}
}
Loading