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 @@ -58,6 +58,11 @@ public class StackServiceComponentResponse {
*/
private String componentDisplayName;

/**
* component version
*/
private String componentVersion;

/**
* component category
*/
Expand Down Expand Up @@ -132,6 +137,7 @@ public StackServiceComponentResponse(ComponentInfo component) {
componentName = component.getName();
componentDisplayName = component.getDisplayName();
componentCategory = component.getCategory();
componentVersion = component.getVersion();
isClient = component.isClient();
isMaster = component.isMaster();
cardinality = component.getCardinality();
Expand Down Expand Up @@ -321,6 +327,25 @@ public void setComponentCategory(String componentCategory) {
this.componentCategory = componentCategory;
}

/**
* Get component version.
*
* @return component version
*/
@ApiModelProperty(name = "component_version")
public String getComponentVersion() {
return componentVersion;
}

/**
* Set the component version.
*
* @param componentVersion component version
*/
public void setComponentVersion(String componentVersion) {
this.componentVersion = componentVersion;
}

/**
* Determine whether the component is a client component.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import org.apache.ambari.server.state.CustomCommandDefinition;
import org.apache.ambari.server.state.RequiredService;
import org.apache.ambari.server.state.ServiceCategory;
import org.apache.ambari.server.state.ServiceInfo;

import io.swagger.annotations.ApiModelProperty;
Expand All @@ -37,6 +38,7 @@ public class StackServiceResponse {
private String stackVersion;
private String serviceName;
private String serviceType;
private ServiceCategory serviceCategory;
private String serviceDisplayName;
private String userName;
private String comments;
Expand Down Expand Up @@ -89,6 +91,7 @@ public class StackServiceResponse {
public StackServiceResponse(ServiceInfo service) {
serviceName = service.getName();
serviceType = service.getServiceType();
serviceCategory = service.getCategory();
serviceDisplayName = service.getDisplayName();
userName = null;
comments = service.getComment();
Expand Down Expand Up @@ -162,6 +165,15 @@ public void setServiceType(String serviceType) {
this.serviceType = serviceType;
}

@ApiModelProperty(name = "service_category")
public ServiceCategory getServiceCategory() {
return serviceCategory;
}

public void setServiceCategory(ServiceCategory serviceCategory) {
this.serviceCategory = serviceCategory;
}

@ApiModelProperty(name = "display_name")
public String getServiceDisplayName() {
return serviceDisplayName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public class StackServiceComponentResourceProvider extends
private static final String COMPONENT_CATEGORY_PROPERTY_ID = PropertyHelper.getPropertyId(
"StackServiceComponents", "component_category");

private static final String COMPONENT_VERSION_PROPERTY_ID = PropertyHelper.getPropertyId(
Copy link
Contributor

Choose a reason for hiding this comment

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

Should also be added to propertyIds:

/**
* The property ids for a StackServiceComponent resource.
*/
private static Set<String> propertyIds = Sets.newHashSet(

"StackServiceComponents", "component_version");

private static final String IS_CLIENT_PROPERTY_ID = PropertyHelper.getPropertyId(
"StackServiceComponents", "is_client");

Expand Down Expand Up @@ -128,6 +131,7 @@ public class StackServiceComponentResourceProvider extends
COMPONENT_NAME_PROPERTY_ID,
COMPONENT_DISPLAY_NAME_PROPERTY_ID,
COMPONENT_CATEGORY_PROPERTY_ID,
COMPONENT_VERSION_PROPERTY_ID,
IS_CLIENT_PROPERTY_ID,
IS_MASTER_PROPERTY_ID,
CARDINALITY_ID,
Expand Down Expand Up @@ -195,6 +199,9 @@ public Set<StackServiceComponentResponse> invoke() throws AmbariException {
setResourceProperty(resource, COMPONENT_CATEGORY_PROPERTY_ID,
response.getComponentCategory(), requestedIds);

setResourceProperty(resource, COMPONENT_VERSION_PROPERTY_ID,
response.getComponentVersion(), requestedIds);

setResourceProperty(resource, IS_CLIENT_PROPERTY_ID,
response.isClient(), requestedIds);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public class StackServiceResourceProvider extends ReadOnlyResourceProvider {
protected static final String SERVICE_TYPE_PROPERTY_ID = PropertyHelper.getPropertyId(
"StackServices", "service_type");

protected static final String SERVICE_CATEGORY_PROPERTY_ID = PropertyHelper.getPropertyId(
Copy link
Contributor

Choose a reason for hiding this comment

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

Should also be added to propertyIds:

/**
* The property ids for a StackVersion resource.
*/
private static Set<String> propertyIds = Sets.newHashSet(

"StackServices", "service_category");

public static final String STACK_NAME_PROPERTY_ID = PropertyHelper.getPropertyId(
"StackServices", "stack_name");

Expand Down Expand Up @@ -117,6 +120,7 @@ public class StackServiceResourceProvider extends ReadOnlyResourceProvider {
private static Set<String> propertyIds = Sets.newHashSet(
SERVICE_NAME_PROPERTY_ID,
SERVICE_TYPE_PROPERTY_ID,
SERVICE_CATEGORY_PROPERTY_ID,
STACK_NAME_PROPERTY_ID,
STACK_VERSION_PROPERTY_ID,
SERVICE_DISPLAY_NAME_PROPERTY_ID,
Expand Down Expand Up @@ -185,11 +189,14 @@ private Resource createResource(StackServiceResponse response, Set<String> reque
setResourceProperty(resource, STACK_NAME_PROPERTY_ID,
response.getStackName(), requestedIds);

setResourceProperty(resource, SERVICE_NAME_PROPERTY_ID,
response.getServiceName(), requestedIds);
setResourceProperty(resource, SERVICE_NAME_PROPERTY_ID,
response.getServiceName(), requestedIds);

setResourceProperty(resource, SERVICE_TYPE_PROPERTY_ID,
response.getServiceType(), requestedIds);

setResourceProperty(resource, SERVICE_TYPE_PROPERTY_ID,
response.getServiceType(), requestedIds);
setResourceProperty(resource, SERVICE_CATEGORY_PROPERTY_ID,
response.getServiceCategory(), requestedIds);

setResourceProperty(resource, STACK_VERSION_PROPERTY_ID,
response.getStackVersion(), requestedIds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.ambari.server.state.ComponentInfo;
import org.apache.ambari.server.state.CustomCommandDefinition;
import org.apache.ambari.server.state.QuickLinksConfigurationInfo;
import org.apache.ambari.server.state.ServiceCategory;
import org.apache.ambari.server.state.ServiceInfo;
import org.apache.ambari.server.state.ServicePropertyInfo;
import org.apache.ambari.server.state.ThemeInfo;
Expand Down Expand Up @@ -209,6 +210,10 @@ public void resolveInternal(
ServiceInfo.ServiceAdvisorType serviceAdvisorType = parent.getServiceAdvisorType();
serviceInfo.setServiceAdvisorType(serviceAdvisorType == null ? ServiceInfo.ServiceAdvisorType.PYTHON : serviceAdvisorType);
}
if (serviceInfo.getCategory() == null) {
ServiceCategory category = parent.getCategory();
serviceInfo.setCategory(category == null ? ServiceCategory.LEGACY : category);
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi Dmitry,
I have a query. Inheritance will be present only for Legacy Stacks and hence services. So, when we say ServiceCategory category = parent.getCategory();, category will be null for new mpacks. In which case we will use the category from current module's metainfo.xml. Considering we have inserted a category to all the existing metainfo.xml files, what is the scenario for Category = LEGACY? Is it just for the very first version of a stack? Even for that, it should take its category from metainfo.xml instead of terming it LEGACY, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't completely understood the issue here.

In case the service is not inherited from other service this code will never be reached, instead the one from StackModule will be executed: https://github.com/d0zen1/ambari/blob/137d82ebfb8db273706c23a352803a8ed671a09b/ambari-server/src/main/java/org/apache/ambari/server/stack/StackModule.java#L356-L364

The general logic follows the following priority rules, given 1 is the highest priority:

  1. Current service category (from service metainfo.xml if defined)
  2. Parent service category (from parent service metainfo.xml if defined)
  3. Default service category (LEGACY)

}
if (serviceInfo.getVersion() == null) {
serviceInfo.setVersion(parent.getVersion());
}
Expand Down Expand Up @@ -602,11 +607,26 @@ private void mergeComponents(
ServiceModule parent, Map<String, StackModule> allStacks, Map<String, ServiceModule> commonServices, Map<String, ExtensionModule> extensions)
throws AmbariException {
serviceInfo.getComponents().clear();

//component version should not inherit from parent service
//make deep copy of all the parent components and set component versions to null
//TODO get rid of this when we move to only standalone stack definitions
Map<String, ComponentModule> parentComponentsCopy = new HashMap<>();
parent.componentModules.values().forEach(componentModule -> parentComponentsCopy.put(componentModule.getId(),
new ComponentModule(new ComponentInfo(componentModule.getModuleInfo()))));
//set nulls to component versions
parentComponentsCopy.values().forEach(componentModule -> componentModule.getModuleInfo().setVersion(null));

Collection<ComponentModule> mergedModules = mergeChildModules(
allStacks, commonServices, extensions, componentModules, parent.componentModules);
allStacks, commonServices, extensions, componentModules, parentComponentsCopy);
componentModules.clear();
for (ComponentModule module : mergedModules) {
if (!module.isDeleted()){
//if the version is not defined for component, set the service version
if (module.getModuleInfo().getVersion() == null) {
module.getModuleInfo().setVersion(serviceInfo.getVersion());
}

componentModules.put(module.getId(), module);
serviceInfo.getComponents().add(module.getModuleInfo());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.apache.ambari.server.state.PropertyInfo;
import org.apache.ambari.server.state.RefreshCommand;
import org.apache.ambari.server.state.RepositoryInfo;
import org.apache.ambari.server.state.ServiceCategory;
import org.apache.ambari.server.state.ServiceInfo;
import org.apache.ambari.server.state.StackInfo;
import org.apache.ambari.server.state.stack.ConfigUpgradePack;
Expand Down Expand Up @@ -353,6 +354,14 @@ private void mergeServicesWithExplicitParent(
mergeServiceWithExplicitParent(service, parent, allStacks, commonServices, extensions);
}else {
serviceInfo.setServiceAdvisorType(ServiceInfo.ServiceAdvisorType.PYTHON);
if (serviceInfo.getCategory() == null) {
serviceInfo.setCategory(ServiceCategory.LEGACY);
}
for (ComponentInfo componentInfo : serviceInfo.getComponents()) {
if (componentInfo.getVersion() == null) {
componentInfo.setVersion(serviceInfo.getVersion());
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ public class ComponentInfo {
private String category;
private boolean deleted;
private String cardinality;


//Should inherit the service version if component version is not defined
//Doesn't inherit version from parent component
private String version;

@XmlElement(name="versionAdvertised")
private Boolean versionAdvertisedField;

Expand Down Expand Up @@ -162,6 +166,8 @@ public ComponentInfo() {
public ComponentInfo(ComponentInfo prototype) {
name = prototype.name;
category = prototype.category;
version = prototype.version;
displayName = prototype.displayName;
deleted = prototype.deleted;
cardinality = prototype.cardinality;
versionAdvertisedField = prototype.versionAdvertisedField;
Expand Down Expand Up @@ -200,6 +206,14 @@ public void setDisplayName(String displayName) {
this.displayName = displayName;
}

public String getVersion() {
return version;
}

public void setVersion(String version) {
this.version = version;
}

public String getCategory() {
return category;
}
Expand Down Expand Up @@ -460,6 +474,7 @@ public boolean equals(Object o) {
ComponentInfo that = (ComponentInfo) o;

if (deleted != that.deleted) return false;
if (version != that.version) return false;
if (autoDeploy != null ? !autoDeploy.equals(that.autoDeploy) : that.autoDeploy != null) return false;
if (cardinality != null ? !cardinality.equals(that.cardinality) : that.cardinality != null) return false;
if (versionAdvertisedField != null ? !versionAdvertisedField.equals(that.versionAdvertisedField) : that.versionAdvertisedField != null) return false;
Expand Down Expand Up @@ -492,6 +507,7 @@ public boolean equals(Object o) {
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = 31 * result + (displayName != null ? displayName.hashCode() : 0);
result = 31 * result + (version != null ? version.hashCode() : 0);
result = 31 * result + (category != null ? category.hashCode() : 0);
result = 31 * result + (deleted ? 1 : 0);
result = 31 * result + (cardinality != null ? cardinality.hashCode() : 0);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.state;

/**
* The category of service.
*/
public enum ServiceCategory {
/**
* The service contains form only master and slave components
*/
SERVER,

/**
* The service contains from only client components
*/
CLIENT,

/**
* The service contains all kind of components
*/
LEGACY
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public class ServiceInfo implements Validable, Cloneable {
private String schemaVersion;

private String name;
private ServiceCategory category;
private String displayName;
private String version;
private String comment;
Expand Down Expand Up @@ -350,6 +351,14 @@ public void setName(String name) {
this.name = name;
}

public ServiceCategory getCategory() {
return category;
}

public void setCategory(ServiceCategory category) {
this.category = category;
}

public String getParent() {
return parent;
}
Expand Down Expand Up @@ -489,6 +498,11 @@ public List<ComponentInfo> getComponents() {
return components;
}

//Used only for testing purposes
public void setComponents(List<ComponentInfo> components) {
this.components = components;
}

/**
* Finds ComponentInfo by component name
* @param componentName name of the component
Expand All @@ -503,6 +517,9 @@ public ComponentInfo getComponentByName(String componentName){
return null;
}
public boolean isClientOnlyService() {
if (ServiceCategory.CLIENT.equals(category)) {
return true;
}
if (components == null || components.isEmpty()) {
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions ambari-server/src/main/resources/properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
"StackServices/stack_name",
"StackServices/stack_version",
"StackServices/service_name",
"StackServices/service_category",
Copy link
Contributor

Choose a reason for hiding this comment

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

properties.json is no longer used, see e77a31a.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Didn't know about this change. Thanks for noticing

"StackServices/display_name",
"StackServices/selection",
"StackServices/user_name",
Expand Down Expand Up @@ -227,6 +228,7 @@
"StackServiceComponents/stack_version",
"StackServiceComponents/service_name",
"StackServiceComponents/component_name",
"StackServiceComponents/component_version",
"StackServiceComponents/display_name",
"StackServiceComponents/component_category",
"StackServiceComponents/is_client",
Expand Down
Loading