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

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

Introduction

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

Prototype

public PutAttributesRequest(String domainName, String itemName,
        java.util.List<ReplaceableAttribute> attributes) 

Source Link

Document

Constructs a new PutAttributesRequest object.

Usage

From source file:com.brighttag.agathon.dao.sdb.SdbCassandraInstanceDao.java

License:Apache License

@Override
public void save(String ring, CassandraInstance instance) {
    PutAttributesRequest request = new PutAttributesRequest(domain(ring), String.valueOf(instance.getId()),
            buildSaveAttributes(instance));
    client.putAttributes(request);/*from w  w  w.  j a  v a2 s  .com*/
}

From source file:com.netflix.simianarmy.aws.conformity.SimpleDBConformityClusterTracker.java

License:Apache License

/** {@inheritDoc} */
@Override// w  w w  .j a  va  2 s .com
public void addOrUpdate(Cluster cluster) {
    List<ReplaceableAttribute> attrs = new ArrayList<ReplaceableAttribute>();
    Map<String, String> fieldToValueMap = cluster.getFieldToValueMap();
    for (Map.Entry<String, String> entry : fieldToValueMap.entrySet()) {
        attrs.add(new ReplaceableAttribute(entry.getKey(), StringUtils.left(entry.getValue(), MAX_ATTR_SIZE),
                true));
    }
    PutAttributesRequest putReqest = new PutAttributesRequest(domain, getSimpleDBItemName(cluster), attrs);
    LOGGER.debug(String.format("Saving cluster %s to SimpleDB domain %s", cluster.getName(), domain));
    this.simpleDBClient.putAttributes(putReqest);
    LOGGER.debug("Successfully saved.");
}

From source file:com.netflix.simianarmy.aws.janitor.SimpleDBJanitorResourceTracker.java

License:Apache License

/** {@inheritDoc} */
@Override//from  w w  w  .  j  av  a 2  s  .co  m
public void addOrUpdate(Resource resource) {
    List<ReplaceableAttribute> attrs = new ArrayList<ReplaceableAttribute>();
    Map<String, String> fieldToValueMap = resource.getFieldToValueMap();
    for (Map.Entry<String, String> entry : fieldToValueMap.entrySet()) {
        attrs.add(new ReplaceableAttribute(entry.getKey(), entry.getValue(), true));
    }
    PutAttributesRequest putReqest = new PutAttributesRequest(domain, getSimpleDBItemName(resource), attrs);
    LOGGER.debug(String.format("Saving resource %s to SimpleDB domain %s", resource.getId(), domain));
    this.simpleDBClient.putAttributes(putReqest);
    LOGGER.debug("Successfully saved.");
}

From source file:com.netflix.simianarmy.aws.SimpleDBRecorder.java

License:Apache License

/** {@inheritDoc} */
@Override/*from   ww  w .j  a  v a 2  s. co  m*/
public void recordEvent(Event evt) {
    String evtTime = String.valueOf(evt.eventTime().getTime());
    List<ReplaceableAttribute> attrs = new LinkedList<ReplaceableAttribute>();
    attrs.add(new ReplaceableAttribute(Keys.id.name(), evt.id(), true));
    attrs.add(new ReplaceableAttribute(Keys.eventTime.name(), evtTime, true));
    attrs.add(new ReplaceableAttribute(Keys.region.name(), evt.region(), true));
    attrs.add(new ReplaceableAttribute(Keys.recordType.name(), "MonkeyEvent", true));
    attrs.add(new ReplaceableAttribute(Keys.monkeyType.name(), enumToValue(evt.monkeyType()), true));
    attrs.add(new ReplaceableAttribute(Keys.eventType.name(), enumToValue(evt.eventType()), true));
    for (Map.Entry<String, String> pair : evt.fields().entrySet()) {
        if (pair.getValue() == null || pair.getValue().equals("") || Keys.KEYSET.contains(pair.getKey())) {
            continue;
        }
        attrs.add(new ReplaceableAttribute(pair.getKey(), pair.getValue(), true));
    }
    // Let pk contain the timestamp so that the same resource can have multiple events.
    String pk = String.format("%s-%s-%s-%s", evt.monkeyType().name(), evt.id(), region, evtTime);
    PutAttributesRequest putReq = new PutAttributesRequest(domain, pk, attrs);
    sdbClient().putAttributes(putReq);

}

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

License:Apache License

private void updateState(TriggerWrapper tw) {
    logDebug("Updating state of Trigger: ", tw.trigger.getFullName());
    String key = TriggerWrapper.getTriggerNameKey(tw.trigger);
    ReplaceableAttribute attr = new ReplaceableAttribute(TRIGGER_STATE, String.valueOf(tw.state), true);
    amazonSimpleDb.putAttributes(new PutAttributesRequest(triggerDomain, key, Collections.singletonList(attr)));
}

From source file:com.tremolosecurity.provisioning.core.providers.AmazonSimpleDBProvider.java

License:Apache License

@Override
public void createUser(User user, Set<String> attributes, Map<String, Object> request)
        throws ProvisioningException {

    int approvalID = 0;

    if (request.containsKey("APPROVAL_ID")) {
        approvalID = (Integer) request.get("APPROVAL_ID");
    }//from   w w w  .  ja  v a 2s . c o  m

    Workflow workflow = (Workflow) request.get("WORKFLOW");

    Iterator<String> it = user.getAttribs().keySet().iterator();

    String userid = null;

    ArrayList<ReplaceableAttribute> attrs = new ArrayList<ReplaceableAttribute>();

    while (it.hasNext()) {
        String attrName = it.next();
        if (attributes.contains(attrName)) {
            Attribute attr = user.getAttribs().get(attrName);

            Iterator<String> vals = attr.getValues().iterator();
            while (vals.hasNext()) {
                attrs.add(new ReplaceableAttribute(attr.getName().toLowerCase(), vals.next(), false));
            }

        }

        if (attrName.equalsIgnoreCase(this.uidAttrName)) {
            userid = user.getAttribs().get(attrName).getValues().get(0);
        }

    }

    if (userid == null) {
        throw new ProvisioningException("No valid userid attribute");
    }

    sdb.putAttributes(new PutAttributesRequest(this.userDomain, userid, attrs));

    this.cfgMgr.getProvisioningEngine().logAction(this.name, true, ActionType.Add, approvalID, workflow,
            "userName", userid);

    for (String attrName : user.getAttribs().keySet()) {
        Attribute attr = user.getAttribs().get(attrName);
        if (!attributes.contains(attr.getName())) {
            continue;
        }

        this.cfgMgr.getProvisioningEngine().logAction(this.name, false, ActionType.Add, approvalID, workflow,
                attrName, user.getAttribs().get(attrName).getValues().get(0));

    }

    boolean ok = false;
    while (!ok) {
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {

        }

        try {
            if (this.findUser(userid, attributes, request) != null) {
                ok = true;
            } else {

            }
        } catch (Exception e) {

        }

    }

    Iterator<String> groupNames = user.getGroups().iterator();

    while (groupNames.hasNext()) {
        String groupName = groupNames.next();

        SelectResult res = this.sdb.select(new SelectRequest(this.getGroupSelect(groupName)));

        if (res.getItems().size() == 0) {
            attrs = new ArrayList<ReplaceableAttribute>();
            attrs.add(new ReplaceableAttribute("cn", groupName, false));
            sdb.putAttributes(new PutAttributesRequest(groupDomain, groupName, attrs));
        }

        attrs = new ArrayList<ReplaceableAttribute>();
        attrs.add(new ReplaceableAttribute(
                GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getGroupMemberAttribute(), userid,
                false));
        sdb.putAttributes(new PutAttributesRequest(this.groupDomain, groupName, attrs));

        this.cfgMgr.getProvisioningEngine().logAction(this.name, false, ActionType.Add, approvalID, workflow,
                "group", groupName);

        ok = false;
        while (!ok) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {

            }

            StringBuffer select = new StringBuffer();
            select.append("SELECT ")
                    .append(GlobalEntries.getGlobalEntries().getConfigManager().getCfg()
                            .getGroupMemberAttribute())
                    .append(" FROM `").append(this.groupDomain).append("` WHERE cn='").append(groupName)
                    .append("' AND ").append(GlobalEntries.getGlobalEntries().getConfigManager().getCfg()
                            .getGroupMemberAttribute())
                    .append("='").append(userid).append("'");

            res = this.sdb.select(new SelectRequest(select.toString()));

            ok = res.getItems().size() > 0;
        }

    }

}

From source file:com.tremolosecurity.provisioning.core.providers.AmazonSimpleDBProvider.java

License:Apache License

@Override
public void syncUser(User user, boolean addOnly, Set<String> attributes, Map<String, Object> request)
        throws ProvisioningException {
    User amazonUser = this.findUser(user.getAttribs().get(this.uidAttrName).getValues().get(0), attributes,
            request);/*from   w  w w  .  j a  v a2s.c  o m*/
    if (amazonUser == null) {
        this.createUser(user, attributes, request);
        return;
    }

    int approvalID = 0;

    if (request.containsKey("APPROVAL_ID")) {
        approvalID = (Integer) request.get("APPROVAL_ID");
    }

    Workflow workflow = (Workflow) request.get("WORKFLOW");

    String userid = user.getAttribs().get(this.uidAttrName).getValues().get(0);

    Set<String> done = new HashSet<String>();

    Iterator<String> amazonAttrNames = amazonUser.getAttribs().keySet().iterator();
    while (amazonAttrNames.hasNext()) {
        String amznAttrName = amazonAttrNames.next();
        done.add(amznAttrName);
        Attribute userAttr = user.getAttribs().get(amznAttrName);
        if (userAttr == null) {
            if (addOnly) {
                //do nothing
            } else {
                ArrayList<com.amazonaws.services.simpledb.model.Attribute> list = new ArrayList<com.amazonaws.services.simpledb.model.Attribute>();
                list.add(new com.amazonaws.services.simpledb.model.Attribute(amznAttrName.toLowerCase(), null));
                sdb.deleteAttributes(
                        new DeleteAttributesRequest(this.userDomain, amazonUser.getUserID(), list));
                boolean ok = false;
                while (!ok) {
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {

                    }

                    StringBuffer select = new StringBuffer();
                    select.append("SELECT uid FROM `").append(this.userDomain).append("` WHERE uid='")
                            .append(userid).append("' AND ").append(amznAttrName).append(" IS NOT NULL");

                    SelectResult res = this.sdb.select(new SelectRequest(select.toString()));

                    ok = res.getItems().size() == 0;
                }
            }
        } else {
            Set<String> vals = new HashSet<String>();
            vals.addAll(userAttr.getValues());

            List<String> amznVals = amazonUser.getAttribs().get(amznAttrName).getValues();

            for (String val : amznVals) {

                if (vals.contains(val)) {
                    vals.remove(val);
                } else {
                    if (!addOnly) {
                        ArrayList<com.amazonaws.services.simpledb.model.Attribute> list = new ArrayList<com.amazonaws.services.simpledb.model.Attribute>();
                        list.add(new com.amazonaws.services.simpledb.model.Attribute(
                                userAttr.getName().toLowerCase(), val));
                        sdb.deleteAttributes(
                                new DeleteAttributesRequest(this.userDomain, amazonUser.getUserID(), list));
                        this.cfgMgr.getProvisioningEngine().logAction(this.name, false, ActionType.Delete,
                                approvalID, workflow, userAttr.getName().toLowerCase(), val);
                        boolean ok = false;
                        while (!ok) {
                            try {
                                Thread.sleep(500);
                            } catch (InterruptedException e) {

                            }

                            StringBuffer select = new StringBuffer();
                            select.append("SELECT uid FROM `").append(this.userDomain).append("` WHERE uid='")
                                    .append(userid).append("' AND ").append(userAttr.getName().toLowerCase())
                                    .append("='").append(val).append("'");

                            SelectResult res = this.sdb.select(new SelectRequest(select.toString()));

                            ok = res.getItems().size() == 0;
                        }
                    }
                }
            }

            if (vals.size() > 0) {
                ArrayList<com.amazonaws.services.simpledb.model.ReplaceableAttribute> list = new ArrayList<com.amazonaws.services.simpledb.model.ReplaceableAttribute>();

                Iterator<String> itv = vals.iterator();

                while (itv.hasNext()) {
                    String val = itv.next();
                    list.add(new com.amazonaws.services.simpledb.model.ReplaceableAttribute(
                            userAttr.getName().toLowerCase(), val, false));
                }

                sdb.putAttributes(new PutAttributesRequest(this.userDomain, amazonUser.getUserID(), list));

                itv = vals.iterator();

                while (itv.hasNext()) {
                    String val = itv.next();
                    this.cfgMgr.getProvisioningEngine().logAction(this.name, false, ActionType.Replace,
                            approvalID, workflow, userAttr.getName().toLowerCase(), val);
                }

                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {

                }

            }

        }

        Iterator<String> itattr = user.getAttribs().keySet().iterator();
        while (itattr.hasNext()) {
            String name = itattr.next();
            if (attributes.contains(name) && !done.contains(name)) {
                ArrayList<com.amazonaws.services.simpledb.model.ReplaceableAttribute> list = new ArrayList<com.amazonaws.services.simpledb.model.ReplaceableAttribute>();
                for (String val : user.getAttribs().get(name).getValues()) {
                    list.add(new com.amazonaws.services.simpledb.model.ReplaceableAttribute(name.toLowerCase(),
                            val, false));
                }

                sdb.putAttributes(new PutAttributesRequest(this.userDomain, amazonUser.getUserID(), list));

                for (String val : user.getAttribs().get(name).getValues()) {
                    this.cfgMgr.getProvisioningEngine().logAction(this.name, false, ActionType.Add, approvalID,
                            workflow, name, val);
                }

                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {

                }
            }
        }

        String select = this.getGroupSelect(amazonUser.getUserID());

        SelectResult res = this.sdb.select(new SelectRequest(select));
        done.clear();
        for (Item group : res.getItems()) {
            String name = group.getName();
            if (!user.getGroups().contains(name) && !addOnly) {
                ArrayList<com.amazonaws.services.simpledb.model.Attribute> list = new ArrayList<com.amazonaws.services.simpledb.model.Attribute>();
                list.add(new com.amazonaws.services.simpledb.model.Attribute(
                        GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getGroupMemberAttribute(),
                        amazonUser.getUserID()));
                sdb.deleteAttributes(new DeleteAttributesRequest(this.groupDomain, name, list));

                this.cfgMgr.getProvisioningEngine().logAction(this.name, false, ActionType.Delete, approvalID,
                        workflow, "group", name);
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {

                }
            }

            done.add(name);
        }

        for (String groupName : user.getGroups()) {
            if (done.contains(groupName)) {
                continue;
            }

            ArrayList<com.amazonaws.services.simpledb.model.ReplaceableAttribute> list = new ArrayList<com.amazonaws.services.simpledb.model.ReplaceableAttribute>();
            list.add(new com.amazonaws.services.simpledb.model.ReplaceableAttribute(
                    GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getGroupMemberAttribute(),
                    amazonUser.getUserID(), false));
            sdb.putAttributes(new PutAttributesRequest(this.groupDomain, groupName, list));
            this.cfgMgr.getProvisioningEngine().logAction(this.name, false, ActionType.Add, approvalID,
                    workflow, "group", groupName);
        }

    }

}

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

License:Apache License

private void putAttributesInternal(String domainName, String id, List<ReplaceableAttribute> attributes,
        int attempt) throws DataAccessException {
    try {//  w  ww .  j  a v a2 s .com
        PutAttributesRequest request = new PutAttributesRequest(domainName, id, attributes);
        sdb.putAttributes(request);
    } 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++;
            putAttributesInternal(domainName, id, attributes, attempt);
        } else {
            throw e;
        }
    }
}

From source file:org.teiid.resource.adpter.simpledb.SimpleDbAPIClass.java

License:Open Source License

/**
 *  Inserts item into given domain.//  w w  w . j a  va2  s. co  m
 * @param domainName
 * @param itemName
 * @param columnsMap
 * @return
 */

public int performInsert(String domainName, String itemName, Map<String, String> columnsMap) {
    List<ReplaceableAttribute> attributes = new ArrayList<ReplaceableAttribute>();
    for (Map.Entry<String, String> column : columnsMap.entrySet()) {
        if (!column.getKey().equals("itemName()")) { //$NON-NLS-1$
            if (column.getValue().matches("^\\[.+\\]$")) { //is multivalued attribute //$NON-NLS-1$
                List<ReplaceableAttribute> multivaluedAttributes = createMultivaluedAttribute(column);
                attributes.addAll(multivaluedAttributes);
            } else { //is just single valued attribute
                attributes.add(new ReplaceableAttribute(column.getKey(), column.getValue(), false));
            }
        }
    }
    PutAttributesRequest putAttributesRequest = new PutAttributesRequest(domainName, itemName, attributes);
    client.putAttributes(putAttributesRequest);
    return 1;
}

From source file:pl.worker.Main.java

public static void putToSDB(String file) {
    AmazonSimpleDBClient simpleDB = new AmazonSimpleDBClient();
    simpleDB.setRegion(Region.getRegion(Regions.US_WEST_2));
    simpleDB.putAttributes(new PutAttributesRequest("leszczynska_project", "Przetworzono plik",
            Arrays.asList(new ReplaceableAttribute("key", file, Boolean.FALSE))));
}