YARN-8300. Fixed NPE in DefaultUpgradeComponentsFinder.

Contributed by Suma Shivaprasad
This commit is contained in:
Eric Yang 2018-05-16 12:38:26 -04:00
parent 6b67161ca3
commit 91357c22ef
2 changed files with 84 additions and 50 deletions

View File

@ -100,55 +100,63 @@ public interface UpgradeComponentsFinder {
targetDef.getComponents().forEach(component -> {
Component currentComp = currentDef.getComponent(component.getName());
if (!Objects.equals(currentComp.getName(), component.getName())) {
if (currentComp != null) {
if (!Objects.equals(currentComp.getName(), component.getName())) {
throw new UnsupportedOperationException(
"changes to component name not supported by upgrade");
}
if (!Objects.equals(currentComp.getDependencies(),
component.getDependencies())) {
throw new UnsupportedOperationException(
"changes to component dependencies not supported by upgrade");
}
if (!Objects.equals(currentComp.getReadinessCheck(),
component.getReadinessCheck())) {
throw new UnsupportedOperationException(
"changes to component readiness check not supported by "
+ "upgrade");
}
if (!Objects.equals(currentComp.getResource(),
component.getResource())) {
throw new UnsupportedOperationException(
"changes to component resource not supported by upgrade");
}
if (!Objects.equals(currentComp.getRunPrivilegedContainer(),
component.getRunPrivilegedContainer())) {
throw new UnsupportedOperationException(
"changes to run privileged container not supported by upgrade");
}
if (!Objects.equals(currentComp.getPlacementPolicy(),
component.getPlacementPolicy())) {
throw new UnsupportedOperationException(
"changes to component placement policy not supported by "
+ "upgrade");
}
if (!Objects.equals(currentComp.getQuicklinks(),
component.getQuicklinks())) {
throw new UnsupportedOperationException(
"changes to component quick links not supported by upgrade");
}
if (!Objects.equals(currentComp.getArtifact(),
component.getArtifact()) || !Objects.equals(
currentComp.getLaunchCommand(), component.getLaunchCommand())
|| !Objects.equals(currentComp.getConfiguration(),
component.getConfiguration())) {
targetComps.add(component);
}
} else{
throw new UnsupportedOperationException(
"changes to component name not supported by upgrade");
}
if (!Objects.equals(currentComp.getDependencies(),
component.getDependencies())) {
throw new UnsupportedOperationException(
"changes to component dependencies not supported by upgrade");
}
if (!Objects.equals(currentComp.getReadinessCheck(),
component.getReadinessCheck())) {
throw new UnsupportedOperationException(
"changes to component readiness check not supported by upgrade");
}
if (!Objects.equals(currentComp.getResource(),
component.getResource())) {
throw new UnsupportedOperationException(
"changes to component resource not supported by upgrade");
}
if (!Objects.equals(currentComp.getRunPrivilegedContainer(),
component.getRunPrivilegedContainer())) {
throw new UnsupportedOperationException(
"changes to run privileged container not supported by upgrade");
}
if (!Objects.equals(currentComp.getPlacementPolicy(),
component.getPlacementPolicy())) {
throw new UnsupportedOperationException(
"changes to component placement policy not supported by upgrade");
}
if (!Objects.equals(currentComp.getQuicklinks(),
component.getQuicklinks())) {
throw new UnsupportedOperationException(
"changes to component quick links not supported by upgrade");
}
if (!Objects.equals(currentComp.getArtifact(),
component.getArtifact()) ||
!Objects.equals(currentComp.getLaunchCommand(),
component.getLaunchCommand()) ||
!Objects.equals(currentComp.getConfiguration(),
component.getConfiguration())) {
targetComps.add(component);
"addition/deletion of components not supported by upgrade. "
+ "Could not find component " + component.getName() + " in "
+ "current service definition.");
}
});
return targetComps;

View File

@ -23,8 +23,11 @@ import org.junit.Assert;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import static org.junit.Assert.assertEquals;
/**
* Tests for {@link UpgradeComponentsFinder.DefaultUpgradeComponentsFinder}.
*/
@ -40,11 +43,34 @@ public class TestDefaultUpgradeComponentsFinder {
targetDef.getComponents().forEach(x -> x.setArtifact(
TestServiceManager.createTestArtifact("v1")));
Assert.assertEquals("all components need upgrade",
assertEquals("all components need upgrade",
targetDef.getComponents(), finder.findTargetComponentSpecs(currentDef,
targetDef));
}
@Test
public void testServiceUpgradeWithNewComponentAddition() {
Service currentDef = ServiceTestUtils.createExampleApplication();
Service targetDef = ServiceTestUtils.createExampleApplication();
Iterator<Component> targetComponentsIter =
targetDef.getComponents().iterator();
Component firstComponent = targetComponentsIter.next();
firstComponent.setName("newComponentA");
try {
finder.findTargetComponentSpecs(currentDef, targetDef);
Assert.fail("Expected error since component does not exist in service "
+ "definition");
} catch (UnsupportedOperationException usoe) {
assertEquals(
"addition/deletion of components not supported by upgrade. Could "
+ "not find component newComponentA in current service "
+ "definition.",
usoe.getMessage());
//Expected
}
}
@Test
public void testComponentArtifactChange() {
Service currentDef = TestServiceManager.createBaseDef("test");
@ -56,7 +82,7 @@ public class TestDefaultUpgradeComponentsFinder {
List<Component> expected = new ArrayList<>();
expected.add(targetDef.getComponents().get(0));
Assert.assertEquals("single components needs upgrade",
assertEquals("single components needs upgrade",
expected, finder.findTargetComponentSpecs(currentDef,
targetDef));
}