public AwsDeployment(AwsDeploymentConfig config, int port) throws Exception { this.config = config; objectMapper = new ObjectMapper(); EnsembleProvider ensembleProvider = buildEnsembleProvider(config.getExhibitorConfig()); this.curatorClient = buildCuratorClient(ensembleProvider, config.getZookeeperConfig()); AwsIdentity identity = AwsIdentity.getIdentity(config); DeploymentPayload payload = new DeploymentPayload(identity.privateIp, port, identity.availabilityZone); this.groupMember = buildGroupMember(curatorClient, config.getZookeeperConfig(), identity.instanceId, payload); }
private CuratorFramework buildCuratorClient( EnsembleProvider ensembleProvider, ZookeeperConfig config) throws Exception { RetryPolicy retryPolicy = buildRetryPolicy(config.getRetryConfig()); CuratorFramework curatorClient = CuratorFrameworkFactory.builder() .ensembleProvider(ensembleProvider) .retryPolicy(retryPolicy) .build(); return curatorClient; }
@After public void afterEach() throws Exception { awsDeployment.close(); zookeeper.close(); exhibitor.close(); metaDataService.close(); }
@Test public void testDeployment() throws Exception { awsDeployment.start(); RetryPolicy retryPolicy = new RetryOneTime(1); try (CuratorFramework client = CuratorFrameworkFactory.newClient(zookeeper.getConnectString(), retryPolicy)) { client.start(); client.blockUntilConnected(); String path = "/test-path/i-1234567890abcdef0"; Thread.sleep(2000); assertNotNull(client.checkExists().forPath(path)); String data = new String(client.getData().forPath(path)); ObjectMapper objectMapper = new ObjectMapper(); DeploymentPayload payload = objectMapper.readValue(data, new TypeReference<DeploymentPayload>() {}); assertEquals("10.158.112.84", payload.getHost()); assertEquals(443, payload.getPort()); assertEquals("us-west-2b", payload.getAvailabilityZone()); } } }
@Before public void beforeEach() throws Exception { zookeeper = new TestingServer(true); exhibitor = buildExhibitor(zookeeper.getPort()); exhibitor.start(); metaDataService = buildMetaDataService(); metaDataService.start(); Config config = ConfigFactory.load("aws-deployment-test") .withValue( "awsDeploymentTest.exhibitor.url", ConfigValueFactory.fromAnyRef(exhibitor.url("/").toString())) .withValue( "awsDeploymentTest.identityUrl", ConfigValueFactory.fromAnyRef(metaDataService.url("/").toString())); awsDeploymentConfig = new AwsDeploymentConfig(config.getConfig("awsDeploymentTest")); awsDeployment = new AwsDeployment(awsDeploymentConfig, 443); }
private EnsembleProvider buildEnsembleProvider(ExhibitorConfig config) throws Exception { Exhibitors exhibitors = new Exhibitors(config.getHostnames(), config.getRestPort(), () -> ""); RetryPolicy retryPolicy = buildRetryPolicy(config.getRetryConfig()); ExhibitorEnsembleProvider ensembleProvider = new ExhibitorEnsembleProvider( exhibitors, new DefaultExhibitorRestClient(), config.getRestUriPath(), config.getPollingMs(), retryPolicy); ensembleProvider.pollForInitialEnsemble(); return ensembleProvider; }