public Instance unmarshall(StaxUnmarshallerContext context) throws Exception { Instance instance = new Instance(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 1; while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) return instance; if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) { if (context.testExpression("InstanceId", targetDepth)) { instance.setInstanceId(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return instance; } } } }
public Instance unmarshall(StaxUnmarshallerContext context) throws Exception { Instance instance = new Instance(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 2; while (true) { int xmlEvent = context.nextEvent(); if (xmlEvent == XmlPullParser.END_DOCUMENT) break; if (xmlEvent == XmlPullParser.START_TAG) { if (context.testExpression("InstanceId", targetDepth)) { instance.setInstanceId(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } } else if (xmlEvent == XmlPullParser.END_TAG) { if (context.getCurrentDepth() < originalDepth) { break; } } } return instance; }
public Observable<String> deRegisterInstanceFromLoadbalancer(String loadBalancer) { if (instanceId == null || loadBalancer == null) { LOG.error("Unable to register instance {}, on load balancer {}.", instanceId, loadBalancer); throw new IllegalStateException(); } try { return Observable.from(elbAsyncClient.deregisterInstancesFromLoadBalancerAsync(new DeregisterInstancesFromLoadBalancerRequest().withLoadBalancerName(loadBalancer).withInstances(new Instance().withInstanceId(instanceId)))) .flatMap(x -> Observable.just(loadBalancer)); } catch (AmazonClientException e) { LOG.error(LogConstants.ERROR_EXECUTING_REQUEST, e); throw new AwsException(e); } }
public Observable<AwsState> pollForInstanceState(final String loadBalancer) { try { return Observable.from(elbAsyncClient.describeInstanceHealthAsync(new DescribeInstanceHealthRequest().withLoadBalancerName(loadBalancer).withInstances(new Instance().withInstanceId(instanceId)))) .flatMap(result -> { Optional<InstanceState> state = result.getInstanceStates().stream().filter(i -> i.getInstanceId().equals(instanceId)).findFirst(); return just(state.map(instanceState -> AwsState.map(instanceState.getState())).orElse(AwsState.UNKNOWN)); }); } catch (AmazonClientException e) { LOG.error(LogConstants.ERROR_EXECUTING_REQUEST, e); throw new AwsException(e); } }
public Observable<String> registerInstanceWithLoadBalancer(String loadBalancer) { if (instanceId == null || loadBalancer == null) { LOG.error("Unable to register instance {}, on load balancer {}.", instanceId, loadBalancer); throw new IllegalStateException(); } try { return Observable.from(elbAsyncClient.registerInstancesWithLoadBalancerAsync(new RegisterInstancesWithLoadBalancerRequest().withLoadBalancerName(loadBalancer).withInstances(new Instance().withInstanceId(instanceId)))) .flatMap(x -> Observable.just(loadBalancer)) .doOnError(t -> LOG.error(LogConstants.ERROR_EXECUTING_REQUEST, t)); } catch (AmazonClientException e) { LOG.error(LogConstants.ERROR_EXECUTING_REQUEST, e); throw new AwsException(e); } }
if (instanceIds != null) { for (String instanceId : instanceIds) { com.amazonaws.services.elasticloadbalancing.model.Instance instance = new com.amazonaws.services.elasticloadbalancing.model.Instance(instanceId); instances.add(instance);
private void addInstancesToElb(String name, List<Instance> instances) { if (instances.isEmpty()) { echo("No instances to add to load balance " + name); return; } // get instance ids Collection<com.amazonaws.services.elasticloadbalancing.model.Instance> ids = new ArrayList<com.amazonaws.services.elasticloadbalancing.model.Instance>(); for (Instance instance : instances) { ids.add(new com.amazonaws.services.elasticloadbalancing.model.Instance(instance.getInstanceId())); } // register the instances to the balancer RegisterInstancesWithLoadBalancerRequest register = new RegisterInstancesWithLoadBalancerRequest(); register.setLoadBalancerName(name); register.setInstances(ids); elb.registerInstancesWithLoadBalancer(register); }
elbVH.setInstances(instances); trgtGrp.getTargets().forEach(trgtHealth -> { instances.add(new com.amazonaws.services.elasticloadbalancing.model.Instance(trgtHealth.getTarget().getId())); }); appElbInstanceMap.get(accntId).add(elbVH);
public Instance unmarshall(StaxUnmarshallerContext context) throws Exception { Instance instance = new Instance(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 1; while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) return instance; if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) { if (context.testExpression("InstanceId", targetDepth)) { instance.setInstanceId(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return instance; } } } }