DeploymentSpec { public static DeploymentSpec fromXml(Reader reader) { return new DeploymentSpecXmlReader().read(reader); } DeploymentSpec(List<Step> steps,
                          Optional<Integer> majorVersion,
                          Optional<AthenzDomain> athenzDomain,
                          Optional<AthenzService> athenzService,
                          String xmlForm); Optional<Integer> majorVersion(); List<Step> steps(); Optional<AthenzDomain> athenzDomain(); Optional<AthenzService> athenzService(); String xmlForm(); Optional<DeploymentInstanceSpec> instance(InstanceName name); DeploymentInstanceSpec requireInstance(String name); DeploymentInstanceSpec requireInstance(InstanceName name); List<InstanceName> instanceNames(); List<DeploymentInstanceSpec> instances(); static DeploymentSpec fromXml(Reader reader); static DeploymentSpec fromXml(String xmlForm); static DeploymentSpec fromXml(String xmlForm, boolean validate); static String toMessageString(Throwable t); @Override boolean equals(Object o); @Override int hashCode(); static final DeploymentSpec empty; }
@Test(expected = IllegalArgumentException.class) public void duplicateProductionTest() { StringReader r = new StringReader( "<deployment version='1.0'>" + " <instance id='default'>" + " <prod>" + " <region active='true'>us-east1</region>" + " <test>us-east1</test>" + " <test>us-east1</test>" + " </prod>" + " </instance>" + "</deployment>" ); DeploymentSpec.fromXml(r); }
@Test(expected = IllegalArgumentException.class) public void productionTestBeforeDeployment() { StringReader r = new StringReader( "<deployment version='1.0'>" + " <instance id='default'>" + " <prod>" + " <test>us-east1</test>" + " <region active='true'>us-east1</region>" + " </prod>" + " </instance>" + "</deployment>" ); DeploymentSpec.fromXml(r); }
@Test(expected = IllegalArgumentException.class) public void productionTestInParallelWithDeployment() { StringReader r = new StringReader( "<deployment version='1.0'>" + " <instance id='default'>" + " <prod>" + " <parallel>" + " <region active='true'>us-east1</region>" + " <test>us-east1</test>" + " </parallel>" + " </prod>" + " </instance>" + "</deployment>" ); DeploymentSpec.fromXml(r); }
@Test(expected=IllegalArgumentException.class) public void globalServiceIdInTest() { StringReader r = new StringReader( "<deployment version='1.0'>" + " <instance id='default'>" + " <test global-service-id='query' />" + " </instance>" + "</deployment>" ); DeploymentSpec.fromXml(r); }
@Test(expected=IllegalArgumentException.class) public void globalServiceIdInStaging() { StringReader r = new StringReader( "<deployment version='1.0'>" + " <instance id='default'>" + " <staging global-service-id='query' />" + " </instance>" + "</deployment>" ); DeploymentSpec.fromXml(r); }
@Test public void maxDelayExceeded() { try { StringReader r = new StringReader( "<deployment>" + " <instance id='default'>" + " <upgrade policy='canary'/>" + " <prod>" + " <region active='true'>us-west-1</region>" + " <delay hours='47'/>" + " <region active='true'>us-central-1</region>" + " <delay minutes='59' seconds='61'/>" + " <region active='true'>us-east-3</region>" + " </prod>" + " </instance>" + "</deployment>" ); DeploymentSpec.fromXml(r); fail("Expected exception due to exceeding the max total delay"); } catch (IllegalArgumentException e) { assertEquals("The total delay specified is PT48H1S but max 48 hours is allowed", e.getMessage()); } }
@Test public void productionSpecWithDuplicateRegions() { StringReader r = new StringReader( "<deployment>" + " <instance id='default'>" + " <prod>" + " <region active='true'>us-west-1</region>" + " <parallel>" + " <region active='true'>us-west-1</region>" + " <region active='true'>us-central-1</region>" + " <region active='true'>us-east-3</region>" + " </parallel>" + " </prod>" + " </instance>" + "</deployment>" ); try { DeploymentSpec.fromXml(r); fail("Expected exception"); } catch (IllegalArgumentException e) { assertEquals("prod.us-west-1 is listed twice in deployment.xml", e.getMessage()); } }
@Test(expected = IllegalArgumentException.class) public void deploymentSpecWithIncreasinglyStrictUpgradePolicies() { StringReader r = new StringReader( "<deployment version='1.0'>" + " <instance id='instance1'>" + " <upgrade policy='conservative'/>" + " </instance>" + " <instance id='instance2' />" + "</deployment>" ); DeploymentSpec.fromXml(r); }
@Test(expected = IllegalArgumentException.class) public void deploymentSpecWithIncreasinglyStrictUpgradePoliciesInParallel() { StringReader r = new StringReader( "<deployment version='1.0'>" + " <instance id='instance0'/>" + " <parallel>" + " <instance id='instance1'>" + " <upgrade policy='conservative'/>" + " </instance>" + " <instance id='instance2'>" + " <upgrade policy='canary'/>" + " </instance>" + " </parallel>" + "</deployment>" ); DeploymentSpec.fromXml(r); }
@Test(expected = IllegalArgumentException.class) public void deploymentSpecWithIncreasinglyStrictUpgradePoliciesAfterParallel() { StringReader r = new StringReader( "<deployment version='1.0'>" + " <parallel>" + " <instance id='instance1'>" + " <upgrade policy='conservative'/>" + " </instance>" + " <instance id='instance2'>" + " <upgrade policy='canary'/>" + " </instance>" + " </parallel>" + " <instance id='instance3'/>" + "</deployment>" ); DeploymentSpec.fromXml(r); }
@Test(expected = IllegalArgumentException.class) public void deploymentSpecWithIllegallyOrderedDeploymentSpec1() { StringReader r = new StringReader( "<deployment>" + " <instance id='default'>" + " <block-change days='sat' hours='10' time-zone='CET'/>" + " <prod>" + " <region active='true'>us-west-1</region>" + " </prod>" + " <block-change days='mon,tue' hours='15-16'/>" + " </instance>" + "</deployment>" ); DeploymentSpec.fromXml(r); }
@Test(expected = IllegalArgumentException.class) public void deploymentSpecWithIllegallyOrderedDeploymentSpec2() { StringReader r = new StringReader( "<deployment>\n" + " <instance id='default'>" + " <block-change days='sat' hours='10' time-zone='CET'/>" + " <test/>" + " <prod>" + " <region active='true'>us-west-1</region>" + " </prod>" + " </instance>" + "</deployment>" ); DeploymentSpec.fromXml(r); }
@Test(expected = IllegalArgumentException.class) public void it_fails_when_athenz_service_is_not_defined() { StringReader r = new StringReader( "<deployment athenz-domain='domain'>" + " <instance id='default'>" + " <prod>" + " <region active='true'>us-west-1</region>" + " </prod>" + " </instance>" + "</deployment>" ); DeploymentSpec.fromXml(r); }
@Test(expected = IllegalArgumentException.class) public void it_fails_when_athenz_service_is_configured_but_not_athenz_domain() { StringReader r = new StringReader( "<deployment>" + " <instance id='default'>" + " <prod athenz-service='service'>" + " <region active='true'>us-west-1</region>" + " </prod>" + " </instance>" + "</deployment>" ); DeploymentSpec.fromXml(r); }
@Test public void endpointDefaultRegions() { var spec = DeploymentSpec.fromXml("" + "<deployment>" + " <instance id='default'>" + " <prod>" + " <region active=\"true\">us-east</region>" + " <region active=\"true\">us-west</region>" + " </prod>" + " <endpoints>" + " <endpoint id=\"foo\" container-id=\"bar\">" + " <region>us-east</region>" + " </endpoint>" + " <endpoint id=\"nalle\" container-id=\"frosk\" />" + " <endpoint container-id=\"quux\" />" + " </endpoints>" + " </instance>" + "</deployment>"); assertEquals(Set.of("us-east"), endpointRegions("foo", spec)); assertEquals(Set.of("us-east", "us-west"), endpointRegions("nalle", spec)); assertEquals(Set.of("us-east", "us-west"), endpointRegions("default", spec)); }