List of usage examples for com.amazonaws.services.ec2.model MonitorInstancesRequest MonitorInstancesRequest
public MonitorInstancesRequest()
From source file:aws.example.ec2.MonitorInstance.java
License:Open Source License
public static void monitorInstance(String instance_id) { final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient(); DryRunSupportedRequest<MonitorInstancesRequest> dry_request = () -> { MonitorInstancesRequest request = new MonitorInstancesRequest().withInstanceIds(instance_id); return request.getDryRunRequest(); };/*from w w w.j a v a 2 s.c o m*/ DryRunResult dry_response = ec2.dryRun(dry_request); if (!dry_response.isSuccessful()) { System.out.printf("Failed dry run to enable monitoring on instance %s", instance_id); throw dry_response.getDryRunResponse(); } MonitorInstancesRequest request = new MonitorInstancesRequest().withInstanceIds(instance_id); ec2.monitorInstances(request); System.out.printf("Successfully enabled monitoring for instance %s", instance_id); }
From source file:com.zotoh.cloudapi.aws.EC2Instance.java
License:Open Source License
@Override public void enableAnalytics(String server) throws InternalException, CloudException { tstEStrArg("instance-id", server); _svc.getCloud().getEC2().monitorInstances(new MonitorInstancesRequest().withInstanceIds(server)); }
From source file:ec2.MonitorInstance.java
License:Open Source License
public static void monitorInstance(String instanceId) { final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient(); DryRunSupportedRequest<MonitorInstancesRequest> monitorInstancesDryRun = () -> { MonitorInstancesRequest request = new MonitorInstancesRequest().withInstanceIds(instanceId); return request.getDryRunRequest(); };//from www . jav a 2s . co m DryRunResult dryRunResponse = ec2.dryRun(monitorInstancesDryRun); if (!dryRunResponse.isSuccessful()) { System.out.printf("Failed dry run to enable monitoring on instance %s", instanceId); throw dryRunResponse.getDryRunResponse(); } MonitorInstancesRequest request = new MonitorInstancesRequest().withInstanceIds(instanceId); ec2.monitorInstances(request); System.out.printf("Successfully enabled monitoring for instance %s", instanceId); }
From source file:org.gridgain.grid.spi.cloud.ec2lite.GridEc2LiteCloudSpi.java
License:GNU General Public License
/** * Runs Amazon EC2 instances by command. * <p>// w w w. j a v a 2s. c o m * Command may be very complex and contain plenty of parameters. * Refer to class documentation for details. * * @param cmd Cloud command. * @throws GridSpiException Thrown if any exception occurs. */ private void runInstances(GridCloudCommand cmd) throws GridSpiException { assert cmd != null; RunInstancesRequest req = createRunInstancesRequest(cmd); Map<String, String> params = cmd.parameters(); if (params != null && Boolean.parseBoolean(params.get(CMD_DRY_RUN_KEY))) { if (log.isDebugEnabled()) log.debug("Dry run - instances run omitted."); return; } RunInstancesResult res; try { res = ec2.runInstances(req); } catch (AmazonClientException e) { throw new GridSpiException("Failed to perform run instances request.", e); } if (log.isDebugEnabled()) log.debug("Sent run instances request [imgId=" + req.getImageId() + ", minCount=" + req.getMinCount() + ", maxCount=" + req.getMaxCount() + ']'); Collection<String> instIds = new LinkedList<String>(); boolean throwEx = false; for (Instance item : res.getReservation().getInstances()) { String instId = item.getInstanceId(); String imgId = item.getImageId(); instIds.add(instId); if (log.isDebugEnabled()) log.debug("Added (ran) new instance [instId=" + instId + ", imgId=" + imgId + ']'); if (!req.getImageId().equals(imgId)) throwEx = true; } if (!instIds.isEmpty()) { if (req.isMonitoring()) { try { ec2.monitorInstances(new MonitorInstancesRequest().withInstanceIds(instIds)); } catch (AmazonClientException e) { U.error(log, "Failed to start instance monitoring.", e); } if (log.isDebugEnabled()) log.debug("Started instances monitoring: " + instIds); } } if (throwEx || instIds.size() != cmd.number()) throw new GridSpiException("Cloud command has not been successfully executed: " + cmd); }
From source file:org.gridgain.grid.util.ec2.GridEc2Helper.java
License:GNU General Public License
/** * @param imgId EC2 image ID./*from ww w .j a v a 2 s . c o m*/ * @param keyPair Key pair name. * @param secGrps Security groups. * @param instType EC2 Instance type. * @param userData Instances user data. * @param count Instance count. * @param enableMon Enable CloudWatch monitoring. * @return List of started instances' IDs. * @throws GridException Thrown in case of any exception. */ private List<String> startInstances(String imgId, String keyPair, Collection<String> secGrps, String instType, String userData, int count, boolean enableMon) throws GridException { RunInstancesRequest req = new RunInstancesRequest(); req.setImageId(imgId); req.setInstanceType(instType); req.setKeyName(keyPair); req.setMaxCount(count); req.setMinCount(count); req.setMonitoring(enableMon); if (!F.isEmpty(secGrps)) req.setSecurityGroups(secGrps); if (userData != null) req.setUserData(new String(Base64.encodeBase64(userData.getBytes()))); RunInstancesResult res; try { res = ec2.runInstances(req); } catch (AmazonClientException ex) { throw new GridException("Failed to perform EC2 run instances request: " + ex.getMessage(), ex); } List<Instance> running = res.getReservation().getInstances(); if (running == null) throw new GridException("Received unexpected EC2 response (instances have not been started)."); List<String> ids = new ArrayList<String>(); for (Instance inst : running) ids.add(inst.getInstanceId()); if (enableMon) { MonitorInstancesRequest mReq = new MonitorInstancesRequest(); mReq.setInstanceIds(ids); try { ec2.monitorInstances(mReq); } catch (AmazonClientException ex) { throw new GridException("Failed to start instances monitoring.", ex); } } return ids; }