Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple version of singleton feature with featureUtility installFeature command #17319

Merged
merged 2 commits into from
May 28, 2021
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 @@ -73,6 +73,7 @@ public class FeatureUtility {
private final static String WEBSPHERE_LIBERTY_GROUP_ID = "com.ibm.websphere.appserver.features";
private final static String BETA_EDITION = "EARLY_ACCESS";
private static String to;
private boolean isInstallServerFeature = false;


private FeatureUtility(FeatureUtilityBuilder builder) throws IOException, InstallException {
Expand Down Expand Up @@ -135,7 +136,7 @@ private FeatureUtility(FeatureUtilityBuilder builder) throws IOException, Instal
overrideEnvMapWithProperties();

fine("additional jsons: " + additionalJsons);
if (!additionalJsons.isEmpty() && additionalJsons != null) {
if (additionalJsons != null && !additionalJsons.isEmpty()) {
jsonsRequired.addAll(additionalJsons);
map.put("json.provided", true);
}
Expand Down Expand Up @@ -169,6 +170,10 @@ private FeatureUtility(FeatureUtilityBuilder builder) throws IOException, Instal
public void setFeatureToExt(Map<String, String> featureToExt) {
this.featureToExt = featureToExt;
}

public void setIsInstallServerFeature(boolean isInstallServerFeature) {
this.isInstallServerFeature = isInstallServerFeature;
}

/**
* Initialize the Install kernel map.
Expand Down Expand Up @@ -437,6 +442,7 @@ public void installFeatures() throws InstallException, IOException {
if (fromDir != null) {
map.put("from.repo", fromDir.toString());
}
map.put("is.install.server.feature", isInstallServerFeature);
Collection<String> resolvedFeatures = (Collection<String>) map.get("action.result");
checkResolvedFeatures(resolvedFeatures);
boolean upgraded = (boolean) map.get("upgrade.complete");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2020 IBM Corporation and others.
* Copyright (c) 2019, 2020, 2021 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -254,6 +254,7 @@ private ExitCode install() {
featureUtility = new FeatureUtility.FeatureUtilityBuilder().setFromDir(fromDir)
.setFeaturesToInstall(featureNames).setNoCache(noCache).setlicenseAccepted(acceptLicense).setAdditionalJsons(additionalJsons).build();
featureUtility.setFeatureToExt(featureToExt);
featureUtility.setIsInstallServerFeature(true);
featureUtility.installFeatures();
} catch (InstallException e) {
logger.log(Level.SEVERE, e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2020 IBM Corporation and others.
* Copyright (c) 2019, 2020, 2021 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -68,7 +68,7 @@ protected static void setupEnv() throws Exception {
unzipDestination = installRoot + "/../featureUtility_fat_wlp/";

// zip up installRoot
minifiedRoot = exportWlp(installRoot, installRoot + "/../temp/wlp.zip", installRoot + "/../featureUtility_fat_wlp/");
minifiedRoot = exportWlp(installRoot, installRoot + "/../temp/wlp.zip", installRoot + "/../featureUtility_fat_wlp");
Log.info(c, methodName, "minified root: " + minifiedRoot);

if(!new File(minifiedRoot).exists()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,46 @@ public void testInstallFeature() throws Exception {
String output = po.getStdout();
assertTrue("Should contain jsp-2.3", output.contains("jsp-2.3"));

// deleteFiles(METHOD_NAME, "com.ibm.websphere.appserver.jsp-2.3", fileLists);
Log.exiting(c, METHOD_NAME);
}

/**
* Test the install of jsp-2.2, jsp-2.3 from maven central.
* Multi-version is not supported with installServerFeature as it cannot be installed to same resource.
*
* @throws Exception
*/
@Test
public void testMultiVersionFeatures() throws Exception {
final String METHOD_NAME = "testMultiVersionFeatures";
Log.entering(c, METHOD_NAME);
replaceWlpProperties("20.0.0.4");
copyFileToMinifiedRoot("etc", "../../publish/propertyFiles/publishRepoOverrideProps/featureUtility.properties");

copyFileToMinifiedRoot("repo/com/ibm/websphere/appserver/features/features/20.0.0.4",
"../../publish/repo/com/ibm/websphere/appserver/features/features/20.0.0.4/features-20.0.0.4.json");

copyFileToMinifiedRoot("repo/io/openliberty/features/features/20.0.0.4",
"../../publish/repo/io/openliberty/features/features/20.0.0.4/features-20.0.0.4.json");

copyFileToMinifiedRoot("repo/io/openliberty/features/jsp-2.3/20.0.0.4",
"../../publish/repo/io/openliberty/features/jsp-2.3/20.0.0.4/jsp-2.3-20.0.0.4.esa");

copyFileToMinifiedRoot("repo/io/openliberty/features/jsp-2.2/20.0.0.4",
"../../publish/repo/io/openliberty/features/jsp-2.2/20.0.0.4/jsp-2.2-20.0.0.4.esa");



writeToProps(minifiedRoot+ "/etc/featureUtility.properties", "featureLocalRepo", minifiedRoot + "/repo/");

String[] param1s = { "installFeature", "jsp-2.2", "jsp-2.3", "--verbose"};
ProgramOutput po = runFeatureUtility(METHOD_NAME, param1s);
assertEquals("Exit code should be 0",0, po.getReturnCode());
String output = po.getStdout();
assertTrue("Should contain jsp-2.2", output.contains("jsp-2.2"));
assertTrue("Should contain jsp-2.3", output.contains("jsp-2.3"));

// deleteFiles(METHOD_NAME, "com.ibm.websphere.appserver.jsp-2.3", fileLists);
Log.exiting(c, METHOD_NAME);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019 IBM Corporation and others.
* Copyright (c) 2019, 2021 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -168,6 +168,27 @@ public void testInstallAutoFeatureServerXml() throws Exception {
Log.exiting(c, METHOD_NAME);
}

/**
* Test the install of jsp-2.2, jsp-2.3 from maven central.
* Multi-version is not supported with installServerFeature as it cannot be installed to same resource.
*
* @throws Exception
*/
@Test
public void testInvalidMultiVersionFeatures() throws Exception {
final String METHOD_NAME = "testInvalidMultiVersionFeatures";
Log.entering(c, METHOD_NAME);

copyFileToMinifiedRoot("usr/servers/serverX", "../../publish/tmp/multiVersionServerXml/server.xml");
String[] param1s = { "installServerFeatures", "serverX", "--verbose"};
ProgramOutput po = runFeatureUtility(METHOD_NAME, param1s);
assertEquals("Exit code should be 21",21, po.getReturnCode());
String output = po.getStdout();
assertTrue("Should contain CWWKF1405E", output.contains("CWWKF1405E"));

// deleteFiles(METHOD_NAME, "com.ibm.websphere.appserver.jsp-2.3", fileLists);
Log.exiting(c, METHOD_NAME);
}


}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<server description="new server">

<!-- Enable features -->
<featureManager>
<feature>jsp-2.2</feature>
<feature>jsp-2.3</feature>
</featureManager>
</server>

Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public class InstallKernelMap implements Map {
private static final String GENERATE_JSON_GROUP_ID_MAP = "generate.json.group.id.map";
private static final String TARGET_JSON_DIR = "target.json.dir";
private static final String LOCALLY_PRESENT_JSONS = "locally.present.jsons";
private static final String IS_INSTALL_SERVER_FEATURE = "is.install.server.feature";

//Headers in Manifest File
private static final String SHORTNAME_HEADER_NAME = "IBM-ShortName";
Expand Down Expand Up @@ -306,6 +307,12 @@ public Object get(Object key) {
} else {
return data.get(IS_FEATURE_UTILITY);
}
} else if (IS_INSTALL_SERVER_FEATURE.equals(key)) {
if (data.get(IS_INSTALL_SERVER_FEATURE) == null) {
return false;
} else {
return data.get(IS_INSTALL_SERVER_FEATURE);
}
} else if (JSON_PROVIDED.equals(key)) {
if (data.get(JSON_PROVIDED) == null) {
return false;
Expand Down Expand Up @@ -506,6 +513,12 @@ public Object put(Object key, Object value) {
} else {
throw new IllegalArgumentException();
}
} else if (IS_INSTALL_SERVER_FEATURE.equals(key)) {
if (value instanceof Boolean) {
data.put(IS_INSTALL_SERVER_FEATURE, value);
} else {
throw new IllegalArgumentException();
}
} else if (DOWNLOAD_FILETYPE.equals(key)) {
if (value instanceof String) {
data.put(DOWNLOAD_FILETYPE, value);
Expand Down Expand Up @@ -869,6 +882,7 @@ public Collection<String> singleFileResolve() {

int alreadyInstalled = 0;
Collection<String> featureToInstall = (Collection<String>) data.get(FEATURES_TO_RESOLVE);

if (data.get(INSTALL_INDIVIDUAL_ESAS) != null) {
try {
if (data.get(INSTALL_INDIVIDUAL_ESAS).equals(Boolean.TRUE)) {
Expand Down Expand Up @@ -931,7 +945,12 @@ public Collection<String> singleFileResolve() {
}
}
resolver = new RepositoryResolver(productDefinitions, installedFeatures, Collections.<IFixInfo> emptySet(), repoList);
resolveResult = resolver.resolveAsSet((Collection<String>) data.get(FEATURES_TO_RESOLVE));
boolean isInstallServerFeature = (Boolean) this.get(IS_INSTALL_SERVER_FEATURE);
if (!isInstallServerFeature) {
resolveResult = resolver.resolve((Collection<String>) data.get(FEATURES_TO_RESOLVE));
} else {
resolveResult = resolver.resolveAsSet((Collection<String>) data.get(FEATURES_TO_RESOLVE));
}
ResolveDirector.resolveAutoFeatures(resolveResult, new RepositoryResolver(productDefinitions, installedFeatures, Collections.<IFixInfo> emptySet(), repoList));

if (!resolveResult.isEmpty()) {
Expand Down