YARN-8300. Fixed NPE in DefaultUpgradeComponentsFinder.
Contributed by Suma Shivaprasad
(cherry picked from 91357c22ef
)
This commit is contained in:
parent
5310542fb4
commit
2c3f300464
|
@ -100,55 +100,63 @@ public interface UpgradeComponentsFinder {
|
||||||
targetDef.getComponents().forEach(component -> {
|
targetDef.getComponents().forEach(component -> {
|
||||||
Component currentComp = currentDef.getComponent(component.getName());
|
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(
|
throw new UnsupportedOperationException(
|
||||||
"changes to component name not supported by upgrade");
|
"addition/deletion of components not supported by upgrade. "
|
||||||
}
|
+ "Could not find component " + component.getName() + " in "
|
||||||
|
+ "current service definition.");
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
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