Example usage for com.amazonaws.services.simpledb.model GetAttributesRequest GetAttributesRequest

List of usage examples for com.amazonaws.services.simpledb.model GetAttributesRequest GetAttributesRequest

Introduction

In this page you can find the example usage for com.amazonaws.services.simpledb.model GetAttributesRequest GetAttributesRequest.

Prototype

public GetAttributesRequest(String domainName, String itemName) 

Source Link

Document

Constructs a new GetAttributesRequest object.

Usage

From source file:com.threepillar.labs.quartz.simpledb.SimpleDbJobStore.java

License:Apache License

/**
 * <p>/*from   www  .  jav a 2  s  .  c  om*/
 * Inform the <code>JobStore</code> that the scheduler has completed the
 * firing of the given <code>Trigger</code> (and the execution its
 * associated <code>Job</code>), and that the
 * <code>{@link org.quartz.JobDataMap}</code> in the given
 * <code>JobDetail</code> should be updated if the <code>Job</code> is
 * stateful.
 * </p>
 */
@Override
public void triggeredJobComplete(SchedulingContext ctxt, Trigger trigger, JobDetail jobDetail,
        int triggerInstCode) {
    logDebug("Completing Job: ", trigger.getFullName());

    String jobKey = JobWrapper.getJobNameKey(jobDetail.getName(), jobDetail.getGroup());
    GetAttributesResult jobresult = amazonSimpleDb
            .getAttributes(new GetAttributesRequest(jobDomain, jobKey).withConsistentRead(Boolean.TRUE));
    JobDetail job = null;
    try {
        job = jobDetailFromAttributes(jobresult.getAttributes());
        if (job.isStateful()) {
            throw new IllegalStateException("TODO: can't handle stateful jobs right now"); // TODO
        }
    } catch (IOException e) {
        log.error("Could not complete job for Trigger: " + trigger.getFullName(), e);
    }

    String triggerKey = TriggerWrapper.getTriggerNameKey(trigger);
    GetAttributesResult result = amazonSimpleDb.getAttributes(
            new GetAttributesRequest(triggerDomain, triggerKey).withConsistentRead(Boolean.TRUE));
    TriggerWrapper tw = null;

    try {
        tw = triggerFromAttributes(result.getAttributes());
    } catch (IOException e) {
        log.error("Could not find Trigger: " + trigger.getFullName(), e);
    }

    // It's possible that the job is null if:
    // 1- it was deleted during execution
    // 2- RAMJobStore is being used only for volatile jobs / triggers
    // from the JDBC job store

    // check for trigger deleted during execution...
    if (tw != null) {
        if (triggerInstCode == Trigger.INSTRUCTION_DELETE_TRIGGER) {

            if (trigger.getNextFireTime() == null) {
                // double check for possible reschedule within job
                // execution, which would cancel the need to delete...
                if (tw.getTrigger().getNextFireTime() == null) {
                    removeTrigger(ctxt, trigger.getName(), trigger.getGroup());
                }
            } else {
                removeTrigger(ctxt, trigger.getName(), trigger.getGroup());
                signaler.signalSchedulingChange(0L);
            }
        } else if (triggerInstCode == Trigger.INSTRUCTION_SET_TRIGGER_COMPLETE) {
            tw.state = TriggerWrapper.STATE_COMPLETE;
            removeTrigger(ctxt, trigger.getName(), trigger.getGroup());
            signaler.signalSchedulingChange(0L);
        } else if (triggerInstCode == Trigger.INSTRUCTION_SET_TRIGGER_ERROR) {
            getLog().info("Trigger " + trigger.getFullName() + " set to ERROR state.");
            tw.state = TriggerWrapper.STATE_ERROR;
            updateState(tw);
            signaler.signalSchedulingChange(0L);
        } else if (triggerInstCode == Trigger.INSTRUCTION_SET_ALL_JOB_TRIGGERS_ERROR) {
            getLog().info("All triggers of Job " + trigger.getFullJobName() + " set to ERROR state.");
            setAllTriggersOfJobToState(trigger.getJobName(), trigger.getJobGroup(), TriggerWrapper.STATE_ERROR);
            signaler.signalSchedulingChange(0L);
        } else if (triggerInstCode == Trigger.INSTRUCTION_SET_ALL_JOB_TRIGGERS_COMPLETE) {
            setAllTriggersOfJobToState(trigger.getJobName(), trigger.getJobGroup(),
                    TriggerWrapper.STATE_COMPLETE);
            signaler.signalSchedulingChange(0L);
        }
    }
}

From source file:org.grails.datastore.mapping.simpledb.util.SimpleDBTemplateImpl.java

License:Apache License

private Item getInternal(String domainName, String id, int attempt) {
    GetAttributesRequest request = new GetAttributesRequest(domainName, id);
    try {//from w  w w . java  2 s.c o  m
        List<Attribute> attributes = sdb.getAttributes(request).getAttributes();
        if (attributes.isEmpty()) {
            return null;
        }

        return new Item(id, attributes);
    } catch (AmazonServiceException e) {
        if (SimpleDBUtil.AWS_ERR_CODE_NO_SUCH_DOMAIN.equals(e.getErrorCode())) {
            throw new IllegalArgumentException("no such domain: " + domainName, e);
        } else if (SimpleDBUtil.AWS_ERR_CODE_SERVICE_UNAVAILABLE.equals(e.getErrorCode())) {
            //retry after a small pause
            SimpleDBUtil.sleepBeforeRetry(attempt);
            attempt++;
            return getInternal(domainName, id, attempt);
        } else {
            throw e;
        }
    }
}

From source file:org.grails.datastore.mapping.simpledb.util.SimpleDBTemplateImpl.java

License:Apache License

private Item getConsistentInternal(String domainName, String id, int attempt) {
    //        String selectExpression = "select * from `" + domainName + "` where id = '"+id+"'"; //todo

    //todo - handle exceptions and retries

    GetAttributesRequest request = new GetAttributesRequest(domainName, id);
    request.setConsistentRead(true);//from  w  w w  .jav  a 2  s. c o  m
    try {
        List<Attribute> attributes = sdb.getAttributes(request).getAttributes();
        if (attributes.isEmpty()) {
            return null;
        }

        return new Item(id, attributes);
    } catch (AmazonServiceException e) {
        if (SimpleDBUtil.AWS_ERR_CODE_NO_SUCH_DOMAIN.equals(e.getErrorCode())) {
            throw new IllegalArgumentException("no such domain: " + domainName, e);
        } else if (SimpleDBUtil.AWS_ERR_CODE_SERVICE_UNAVAILABLE.equals(e.getErrorCode())) {
            //retry after a small pause
            SimpleDBUtil.sleepBeforeRetry(attempt);
            attempt++;
            return getConsistentInternal(domainName, id, attempt);
        } else {
            throw e;
        }
    }
}

From source file:squash.booking.lambdas.core.OptimisticPersister.java

License:Apache License

@Override
public ImmutablePair<Optional<Integer>, Set<Attribute>> get(String itemName) {

    if (!initialised) {
        throw new IllegalStateException("The optimistic persister has not been initialised");
    }//from   w  w w  .  j a  va  2  s.  c om

    logger.log("About to get all active attributes from simpledb item: " + itemName);

    AmazonSimpleDB client = getSimpleDBClient();

    // Do a consistent read - to ensure we get correct version number
    GetAttributesRequest simpleDBRequest = new GetAttributesRequest(simpleDbDomainName, itemName);
    logger.log("Using simpleDB domain: " + simpleDbDomainName);

    simpleDBRequest.setConsistentRead(true);
    GetAttributesResult result = client.getAttributes(simpleDBRequest);
    List<Attribute> attributes = result.getAttributes();

    // Get the version number and other attributes.
    Optional<Integer> version = Optional.empty();
    Set<Attribute> nonVersionAttributes = new HashSet<>();
    if (attributes.size() > 0) {
        // If we have any attributes, we'll always have a version number
        Attribute versionNumberAttribute = attributes.stream()
                .filter(attribute -> attribute.getName().equals(versionAttributeName)).findFirst().get();
        version = Optional.of(Integer.parseInt(versionNumberAttribute.getValue()));
        logger.log("Retrieved version number: " + versionNumberAttribute.getValue());
        attributes.remove(versionNumberAttribute);

        // Add all active attributes (i.e. those not pending deletion)
        nonVersionAttributes.addAll(attributes.stream()
                .filter(attribute -> !attribute.getValue().startsWith("Inactive")).collect(Collectors.toSet()));
    }
    logger.log("Got all attributes from simpledb");

    return new ImmutablePair<>(version, nonVersionAttributes);
}

From source file:wwutil.jsoda.SimpleDBService.java

License:Mozilla Public License

public <T> T getObj(Class<T> modelClass, Object id, Object rangeKey) throws Exception {
    if (id == null)
        throw new IllegalArgumentException("Id cannot be null.");

    String modelName = jsoda.getModelName(modelClass);
    String table = jsoda.getModelTable(modelName);
    String idValue = makeIdValue(modelName, id, rangeKey);
    GetAttributesResult result = sdbClient.getAttributes(new GetAttributesRequest(table, idValue));
    if (result.getAttributes().size() == 0)
        return null; // not existed.
    return buildLoadObj(modelClass, modelName, idValue, result.getAttributes(), null);

}