YARN-8300. Fixed NPE in DefaultUpgradeComponentsFinder.
Contributed by Suma Shivaprasad
(cherry picked from 91357c22ef
)
This commit is contained in:
parent
5310542fb4
commit
2c3f300464
|
@ -100,6 +100,7 @@ public interface UpgradeComponentsFinder {
|
||||||
targetDef.getComponents().forEach(component -> {
|
targetDef.getComponents().forEach(component -> {
|
||||||
Component currentComp = currentDef.getComponent(component.getName());
|
Component currentComp = currentDef.getComponent(component.getName());
|
||||||
|
|
||||||
|
if (currentComp != null) {
|
||||||
if (!Objects.equals(currentComp.getName(), component.getName())) {
|
if (!Objects.equals(currentComp.getName(), component.getName())) {
|
||||||
throw new UnsupportedOperationException(
|
throw new UnsupportedOperationException(
|
||||||
"changes to component name not supported by upgrade");
|
"changes to component name not supported by upgrade");
|
||||||
|
@ -114,16 +115,17 @@ public interface UpgradeComponentsFinder {
|
||||||
if (!Objects.equals(currentComp.getReadinessCheck(),
|
if (!Objects.equals(currentComp.getReadinessCheck(),
|
||||||
component.getReadinessCheck())) {
|
component.getReadinessCheck())) {
|
||||||
throw new UnsupportedOperationException(
|
throw new UnsupportedOperationException(
|
||||||
"changes to component readiness check not supported by upgrade");
|
"changes to component readiness check not supported by "
|
||||||
|
+ "upgrade");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Objects.equals(currentComp.getResource(),
|
if (!Objects.equals(currentComp.getResource(),
|
||||||
component.getResource())) {
|
component.getResource())) {
|
||||||
|
|
||||||
throw new UnsupportedOperationException(
|
throw new UnsupportedOperationException(
|
||||||
"changes to component resource not supported by upgrade");
|
"changes to component resource not supported by upgrade");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!Objects.equals(currentComp.getRunPrivilegedContainer(),
|
if (!Objects.equals(currentComp.getRunPrivilegedContainer(),
|
||||||
component.getRunPrivilegedContainer())) {
|
component.getRunPrivilegedContainer())) {
|
||||||
throw new UnsupportedOperationException(
|
throw new UnsupportedOperationException(
|
||||||
|
@ -133,7 +135,8 @@ public interface UpgradeComponentsFinder {
|
||||||
if (!Objects.equals(currentComp.getPlacementPolicy(),
|
if (!Objects.equals(currentComp.getPlacementPolicy(),
|
||||||
component.getPlacementPolicy())) {
|
component.getPlacementPolicy())) {
|
||||||
throw new UnsupportedOperationException(
|
throw new UnsupportedOperationException(
|
||||||
"changes to component placement policy not supported by upgrade");
|
"changes to component placement policy not supported by "
|
||||||
|
+ "upgrade");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Objects.equals(currentComp.getQuicklinks(),
|
if (!Objects.equals(currentComp.getQuicklinks(),
|
||||||
|
@ -143,13 +146,18 @@ public interface UpgradeComponentsFinder {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Objects.equals(currentComp.getArtifact(),
|
if (!Objects.equals(currentComp.getArtifact(),
|
||||||
component.getArtifact()) ||
|
component.getArtifact()) || !Objects.equals(
|
||||||
!Objects.equals(currentComp.getLaunchCommand(),
|
currentComp.getLaunchCommand(), component.getLaunchCommand())
|
||||||
component.getLaunchCommand()) ||
|
|| !Objects.equals(currentComp.getConfiguration(),
|
||||||
!Objects.equals(currentComp.getConfiguration(),
|
|
||||||
component.getConfiguration())) {
|
component.getConfiguration())) {
|
||||||
targetComps.add(component);
|
targetComps.add(component);
|
||||||
}
|
}
|
||||||
|
} else{
|
||||||
|
throw new UnsupportedOperationException(
|
||||||
|
"addition/deletion of components not supported by upgrade. "
|
||||||
|
+ "Could not find component " + component.getName() + " in "
|
||||||
|
+ "current service definition.");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return targetComps;
|
return targetComps;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,11 @@ import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link UpgradeComponentsFinder.DefaultUpgradeComponentsFinder}.
|
* Tests for {@link UpgradeComponentsFinder.DefaultUpgradeComponentsFinder}.
|
||||||
*/
|
*/
|
||||||
|
@ -40,11 +43,34 @@ public class TestDefaultUpgradeComponentsFinder {
|
||||||
targetDef.getComponents().forEach(x -> x.setArtifact(
|
targetDef.getComponents().forEach(x -> x.setArtifact(
|
||||||
TestServiceManager.createTestArtifact("v1")));
|
TestServiceManager.createTestArtifact("v1")));
|
||||||
|
|
||||||
Assert.assertEquals("all components need upgrade",
|
assertEquals("all components need upgrade",
|
||||||
targetDef.getComponents(), finder.findTargetComponentSpecs(currentDef,
|
targetDef.getComponents(), finder.findTargetComponentSpecs(currentDef,
|
||||||
targetDef));
|
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
|
@Test
|
||||||
public void testComponentArtifactChange() {
|
public void testComponentArtifactChange() {
|
||||||
Service currentDef = TestServiceManager.createBaseDef("test");
|
Service currentDef = TestServiceManager.createBaseDef("test");
|
||||||
|
@ -56,7 +82,7 @@ public class TestDefaultUpgradeComponentsFinder {
|
||||||
List<Component> expected = new ArrayList<>();
|
List<Component> expected = new ArrayList<>();
|
||||||
expected.add(targetDef.getComponents().get(0));
|
expected.add(targetDef.getComponents().get(0));
|
||||||
|
|
||||||
Assert.assertEquals("single components needs upgrade",
|
assertEquals("single components needs upgrade",
|
||||||
expected, finder.findTargetComponentSpecs(currentDef,
|
expected, finder.findTargetComponentSpecs(currentDef,
|
||||||
targetDef));
|
targetDef));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue