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 @@ -74,8 +74,9 @@
import org.apache.ambari.server.state.ComponentInfo;
import org.apache.ambari.server.state.DependencyInfo;
import org.apache.ambari.server.state.ExtensionInfo;
import org.apache.ambari.server.state.Module;
import org.apache.ambari.server.state.Mpack;
import org.apache.ambari.server.state.OperatingSystemInfo;
import org.apache.ambari.server.state.Packlet;
import org.apache.ambari.server.state.PropertyInfo;
import org.apache.ambari.server.state.RepositoryInfo;
import org.apache.ambari.server.state.Service;
Expand Down Expand Up @@ -694,12 +695,12 @@ public MpackResponse registerMpack(MpackRequest mpackRequest) throws IOException
}

/**
* Gets the packlet information for given mpack.
* Gets the module information for given mpack.
* @param mpackId
* @return List of Packlets.
* @return List of Modules.
*/
public List<Packlet> getPacklets(Long mpackId) {
return mpackManager.getPacklets(mpackId);
public List<Module> getModules(Long mpackId) {
return mpackManager.getModules(mpackId);
}


Expand Down Expand Up @@ -1655,4 +1656,26 @@ KerberosDescriptor readKerberosDescriptorFromFile(String fileLocation) throws Am
public File getCommonWidgetsDescriptorFile() {
return commonWidgetsDescriptorFile;
}

/***
* Fetch all mpacks from mpackMap
* @return all mpacks from mpackMap - in memory data structure
*/
public Collection<Mpack> getMpacks() {
if (mpackManager.getMpackMap() != null) {
return mpackManager.getMpackMap().values();
}
return Collections.emptySet();
}

/***
* Fetch a particular mpack based on mpackid
* @return a single mpack
*/
public Mpack getMpack(Long mpackId) {
if (mpackManager.getMpackMap() != null && mpackManager.getMpackMap().containsKey(mpackId)) {
return mpackManager.getMpackMap().get(mpackId);
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
import org.apache.ambari.server.state.ConfigHelper;
import org.apache.ambari.server.state.HostState;
import org.apache.ambari.server.state.MaintenanceState;
import org.apache.ambari.server.state.Module;
import org.apache.ambari.server.state.OsSpecific;
import org.apache.ambari.server.state.Packlet;
import org.apache.ambari.server.state.Service;
import org.apache.ambari.server.state.ServiceComponent;
import org.apache.ambari.server.state.ServiceComponentFactory;
Expand Down Expand Up @@ -942,12 +942,12 @@ ExecutionCommand getExecutionCommand(Cluster cluster,
void saveConfigGroupUpdate(ConfigGroupRequest configGroupRequest, ConfigGroupResponse configGroupResponse);

/**
* Fetch the packlet info for a given mpack.
* Fetch the module info for a given mpack.
*
* @param mpackId
* @return List of packlets
* @return List of modules
*/
List<Packlet> getPacklets(Long mpackId);
List<Module> getModules(Long mpackId);

/**
* Get the software registries identified by the given request objects.
Expand Down Expand Up @@ -992,5 +992,18 @@ Set<RegistryResponse> getRegistries(Set<RegistryRequest> requests)
* @throws AuthorizationException
*/
Set<ServiceConfigVersionResponse> createServiceConfigVersion(Set<ServiceConfigVersionRequest> requests) throws AmbariException, AuthorizationException;

/***
* Fetch all mpacks
* @return
*/
Set<MpackResponse> getMpacks();

/***
* Fetch an mpack based on id
* @param mpackId
* @return
*/
MpackResponse getMpack(Long mpackId);
}

Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,10 @@
import org.apache.ambari.server.state.Host;
import org.apache.ambari.server.state.HostState;
import org.apache.ambari.server.state.MaintenanceState;
import org.apache.ambari.server.state.Module;
import org.apache.ambari.server.state.Mpack;
import org.apache.ambari.server.state.OperatingSystemInfo;
import org.apache.ambari.server.state.OsSpecific;
import org.apache.ambari.server.state.Packlet;
import org.apache.ambari.server.state.PropertyDependencyInfo;
import org.apache.ambari.server.state.PropertyInfo;
import org.apache.ambari.server.state.PropertyInfo.PropertyType;
Expand Down Expand Up @@ -577,16 +578,34 @@ private Set<RegistryResponse> getRegistries(RegistryRequest request)
@Override
public MpackResponse registerMpack(MpackRequest request)
throws IOException, AuthorizationException, ResourceAlreadyExistsException{


MpackResponse mpackResponse = ambariMetaInfo.registerMpack(request);
updateStacks();
return mpackResponse;
}

@Override
public List<Packlet> getPacklets(Long mpackId) {
return ambariMetaInfo.getPacklets(mpackId);
public Set<MpackResponse> getMpacks(){
Collection<Mpack> mpacks = ambariMetaInfo.getMpacks();
Set<MpackResponse> responseSet = new HashSet<>();
for (Mpack mpack : mpacks){
responseSet.add(new MpackResponse(mpack));
}
return responseSet;
}

@Override
public MpackResponse getMpack(Long mpackId) {
Mpack mpack = ambariMetaInfo.getMpack(mpackId);
if (mpack != null) {
return new MpackResponse(mpack);
}else{
return null;
}
}

@Override
public List<Module> getModules(Long mpackId) {
return ambariMetaInfo.getModules(mpackId);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class MpackResponse {
private String mpackUri;
private Long registryId;
private String stackId;
private String description;

public MpackResponse(Mpack mpack) {
this.mpackId = mpack.getMpackId();
Expand All @@ -41,6 +42,7 @@ public MpackResponse(Mpack mpack) {
this.mpackName = mpack.getName();
this.registryId = mpack.getRegistryId();
this.stackId = mpack.getStackId();
this.description = mpack.getDescription();
}

public String getMpackVersion() {
Expand Down Expand Up @@ -91,6 +93,16 @@ public void setMpackId(Long mpackId) {
this.mpackId = mpackId;
}


public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}


@Override
public int hashCode() {
int result = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
import org.apache.ambari.server.registry.Registry;
import org.apache.ambari.server.registry.RegistryMpack;
import org.apache.ambari.server.registry.RegistryMpackVersion;
import org.apache.ambari.server.state.Packlet;
import org.apache.ambari.server.state.Module;
import org.apache.ambari.server.state.StackId;
import org.apache.commons.lang.Validate;

Expand All @@ -74,7 +74,8 @@ public class MpackResourceProvider extends AbstractControllerResourceProvider {
public static final String MPACK_NAME = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "mpack_name";
public static final String MPACK_VERSION = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "mpack_version";
public static final String MPACK_URI = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "mpack_uri";
public static final String PACKLETS = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "packlets";
public static final String MODULES = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "modules";
public static final String MPACK_DESC = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "description";
public static final String STACK_NAME_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "stack_name";
public static final String STACK_VERSION_PROPERTY_ID =
RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "stack_version";
Expand Down Expand Up @@ -108,7 +109,8 @@ public class MpackResourceProvider extends AbstractControllerResourceProvider {
PROPERTY_IDS.add(MPACK_NAME);
PROPERTY_IDS.add(MPACK_VERSION);
PROPERTY_IDS.add(MPACK_URI);
PROPERTY_IDS.add(PACKLETS);
PROPERTY_IDS.add(MPACK_DESC);
PROPERTY_IDS.add(MODULES);
PROPERTY_IDS.add(STACK_NAME_PROPERTY_ID);
PROPERTY_IDS.add(STACK_VERSION_PROPERTY_ID);

Expand Down Expand Up @@ -146,10 +148,11 @@ public RequestStatus createResourcesAuthorized(final Request request)
notifyCreate(Resource.Type.Mpack, request);
Resource resource = new ResourceImpl(Resource.Type.Mpack);
resource.setProperty(MPACK_ID, response.getMpackId());
resource.setProperty(REGISTRY_ID, response.getRegistryId());
resource.setProperty(MPACK_NAME, response.getMpackName());
resource.setProperty(MPACK_VERSION, response.getMpackVersion());
resource.setProperty(MPACK_URI, response.getMpackUri());
resource.setProperty(MPACK_DESC, response.getDescription());
resource.setProperty(REGISTRY_ID, response.getRegistryId());
associatedResources.add(resource);
return getRequestStatus(null, associatedResources);
}
Expand Down Expand Up @@ -240,17 +243,18 @@ public Set<Resource> getResources(Request request, Predicate predicate)
Long mpackId = null;
if (predicate == null) {
// Fetch all mpacks
List<MpackEntity> entities = mpackDAO.findAll();
if (null == entities) {
entities = Collections.emptyList();
Set<MpackResponse> responses = (HashSet)getManagementController().getMpacks();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either change AmbariManagementController#getMpacks() to return Set instead of Collection, or declare responses as Collection. Both are better than this unchecked cast.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes looks like i changed in AmbariManagementControllerImpl but not in AmbariManagementController. Thanks!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved.

if (null == responses) {
responses = Collections.emptySet();
}
for (MpackEntity entity : entities) {
for (MpackResponse response : responses){
Resource resource = new ResourceImpl(Resource.Type.Mpack);
resource.setProperty(MPACK_ID, entity.getMpackId());
resource.setProperty(MPACK_NAME, entity.getMpackName());
resource.setProperty(MPACK_VERSION, entity.getMpackVersion());
resource.setProperty(MPACK_URI, entity.getMpackUri());
resource.setProperty(REGISTRY_ID, entity.getRegistryId());
resource.setProperty(MPACK_ID, response.getMpackId());
resource.setProperty(MPACK_NAME, response.getMpackName());
resource.setProperty(MPACK_VERSION, response.getMpackVersion());
resource.setProperty(MPACK_URI, response.getMpackUri());
resource.setProperty(MPACK_DESC, response.getDescription());
resource.setProperty(REGISTRY_ID, response.getRegistryId());
results.add(resource);
}
} else {
Expand All @@ -262,12 +266,15 @@ public Set<Resource> getResources(Request request, Predicate predicate)
StackEntity stackEntity = stackDAO.find(stackName, stackVersion);
mpackId = stackEntity.getCurrentMpackId();
if (mpackId != null) {
MpackEntity entity = mpackDAO.findById(mpackId);
MpackResponse response = getManagementController().getMpack(mpackId);
Resource resource = new ResourceImpl(Resource.Type.Mpack);
if (null != entity) {
resource.setProperty(MPACK_ID, entity.getMpackId());
resource.setProperty(MPACK_NAME, entity.getMpackName());
resource.setProperty(MPACK_VERSION, entity.getMpackVersion());
if (null != response) {
resource.setProperty(MPACK_ID, response.getMpackId());
resource.setProperty(MPACK_NAME, response.getMpackName());
resource.setProperty(MPACK_VERSION, response.getMpackVersion());
resource.setProperty(MPACK_URI, response.getMpackUri());
resource.setProperty(MPACK_DESC, response.getDescription());
resource.setProperty(REGISTRY_ID, response.getRegistryId());
resource.setProperty(STACK_NAME_PROPERTY_ID, stackName);
resource.setProperty(STACK_VERSION_PROPERTY_ID, stackVersion);
results.add(resource);
Expand All @@ -281,18 +288,19 @@ public Set<Resource> getResources(Request request, Predicate predicate)
if (objMpackId != null)
mpackId = Long.valueOf((String) objMpackId);

MpackEntity entity = mpackDAO.findById(mpackId);
Resource resource = new ResourceImpl(Resource.Type.Mpack);
if (null != entity) {
resource.setProperty(MPACK_ID, entity.getMpackId());
resource.setProperty(MPACK_NAME, entity.getMpackName());
resource.setProperty(MPACK_VERSION, entity.getMpackVersion());
resource.setProperty(MPACK_URI, entity.getMpackUri());
resource.setProperty(REGISTRY_ID, entity.getRegistryId());
List<Packlet> packlets = getManagementController().getPacklets(entity.getMpackId());
resource.setProperty(PACKLETS, packlets);
results.add(resource);
}
MpackResponse response = getManagementController().getMpack(mpackId);
Resource resource = new ResourceImpl(Resource.Type.Mpack);
if (null != response) {
resource.setProperty(MPACK_ID, response.getMpackId());
resource.setProperty(MPACK_NAME, response.getMpackName());
resource.setProperty(MPACK_VERSION, response.getMpackVersion());
resource.setProperty(MPACK_URI, response.getMpackUri());
resource.setProperty(MPACK_DESC, response.getDescription());
resource.setProperty(REGISTRY_ID, response.getRegistryId());
List<Module> modules = getManagementController().getModules(response.getMpackId());
resource.setProperty(MODULES, modules);
results.add(resource);
}
}
if (results.isEmpty()) {
throw new NoSuchResourceException(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* 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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this.

*
* 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.controller.internal;

import java.util.Collection;
Expand Down
Loading