Example usage for com.google.common.collect ImmutableMap toString

List of usage examples for com.google.common.collect ImmutableMap toString

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableMap toString.

Prototype

@Override
    public String toString() 

Source Link

Usage

From source file:com.baasbox.service.storage.StatisticsService.java

public static ImmutableMap data() throws SqlInjectionException, InvalidCollectionException {
    if (BaasBoxLogger.isTraceEnabled())
        BaasBoxLogger.trace("Method Start");
    UserDao userDao = UserDao.getInstance();
    CollectionDao collDao = CollectionDao.getInstance();
    AssetDao assetDao = AssetDao.getInstance();
    FileDao fileDao = FileDao.getInstance();
    ODatabaseRecordTx db = DbHelper.getConnection();

    long usersCount = userDao.getCount();
    long assetsCount = assetDao.getCount();
    long collectionsCount = collDao.getCount();
    long filesCount = fileDao.getCount();

    List<ODocument> collections = collDao.get(QueryParams.getInstance());
    ArrayList<ImmutableMap> collMap = collectionsDetails(collections);
    ImmutableMap response = ImmutableMap.of("users", usersCount, "collections", collectionsCount,
            "collections_details", collMap, "assets", assetsCount, "files", filesCount);
    if (BaasBoxLogger.isDebugEnabled())
        BaasBoxLogger.debug(response.toString());
    if (BaasBoxLogger.isTraceEnabled())
        BaasBoxLogger.trace("Method End");
    return response;
}

From source file:org.apache.brooklyn.core.config.external.vault.VaultExternalConfigSupplier.java

protected JsonObject apiGet(String path, ImmutableMap<String, String> headers) {
    try {//from  ww w.ja  va2 s.co  m
        String uri = Urls.mergePaths(endpoint, path);
        LOG.debug("Vault request - GET: {}", uri);
        LOG.debug("Vault request - headers: {}", headers.toString());
        HttpToolResponse response = HttpTool.httpGet(httpClient, Urls.toUri(uri), headers);
        LOG.debug("Vault response - code: {} {}",
                new Object[] { Integer.toString(response.getResponseCode()), response.getReasonPhrase() });
        LOG.debug("Vault response - headers: {}", response.getHeaderLists().toString());
        String responseBody = new String(response.getContent(), CHARSET_NAME);
        LOG.debug("Vault response - body: {}", responseBody);
        if (HttpTool.isStatusCodeHealthy(response.getResponseCode())) {
            return gson.fromJson(responseBody, JsonObject.class);
        } else {
            throw new IllegalStateException("HTTP request returned error");
        }
    } catch (UnsupportedEncodingException e) {
        throw Exceptions.propagate(e);
    }
}

From source file:org.apache.brooklyn.core.config.external.vault.VaultExternalConfigSupplier.java

protected JsonObject apiPost(String path, ImmutableMap<String, String> headers,
        ImmutableMap<String, String> requestData) {
    try {/*  w w w . jav  a  2 s.c  o  m*/
        String body = gson.toJson(requestData);
        String uri = Urls.mergePaths(endpoint, path);
        LOG.debug("Vault request - POST: {}", uri);
        LOG.debug("Vault request - headers: {}", headers.toString());
        LOG.debug("Vault request - body: {}", body);
        HttpToolResponse response = HttpTool.httpPost(httpClient, Urls.toUri(uri), headers,
                body.getBytes(CHARSET_NAME));
        LOG.debug("Vault response - code: {} {}",
                new Object[] { Integer.toString(response.getResponseCode()), response.getReasonPhrase() });
        LOG.debug("Vault response - headers: {}", response.getHeaderLists().toString());
        String responseBody = new String(response.getContent(), CHARSET_NAME);
        LOG.debug("Vault response - body: {}", responseBody);
        if (HttpTool.isStatusCodeHealthy(response.getResponseCode())) {
            return gson.fromJson(responseBody, JsonObject.class);
        } else {
            throw new IllegalStateException("HTTP request returned error");
        }
    } catch (UnsupportedEncodingException e) {
        throw Exceptions.propagate(e);
    }
}

From source file:watchserver.util.WatchEventListener.java

private void callRaptureAction(EventType et, FileChangeEvent fe) {
    String actionForEvent = getActionForEvent(et);

    if (!actionForEvent.isEmpty()) {
        //get the action type
        Scheme scheme = new RaptureURI(actionForEvent).getScheme();
        ImmutableMap<String, String> params = ImmutableMap.of("filetoprocess",
                fe.getFile().getName().toString());

        switch (scheme) {
        case SCRIPT:
            String runScript = Kernel.getScript().runScript(ContextFactory.getKernelUser(), actionForEvent,
                    params);/*from  w  w w .  ja  v a 2s  . co  m*/
            log.info("Started script: " + runScript + " with params: " + params.toString());
            break;
        case WORKFLOW:
            String createWorkOrder = Kernel.getDecision().createWorkOrder(ContextFactory.getKernelUser(),
                    actionForEvent, params);
            log.info("Started workorder: " + createWorkOrder + " with params: " + params.toString());
            break;
        default:
            log.error(scheme + " is not supported for " + folder
                    + FilenameUtils.getName(fe.getFile().getName().getBaseName()));
            break;
        }
    } else {
        log.error(et + " has no associated action for monitor on " + folder);
    }

}

From source file:org.apache.usergrid.persistence.core.migration.schema.MigrationManagerImpl.java

/**
 * Check if they keyspace exists.  If it doesn't create it
 *//*from   w  w w  .j  a v a 2s  .c  om*/
private void testAndCreateKeyspace() throws ConnectionException {

    KeyspaceDefinition keyspaceDefinition = null;

    try {
        keyspaceDefinition = keyspace.describeKeyspace();

    } catch (NotFoundException nfe) {
        //if we execute this immediately after a drop keyspace in 1.2.x, Cassandra is returning the NFE instead of a BadRequestException
        //swallow and log, then continue to create the keyspaces.
        logger.info("Received a NotFoundException when attempting to describe keyspace.  It does not exist");
    } catch (Exception e) {
        AstayanxUtils.isKeyspaceMissing("Unable to connect to cassandra", e);
    }

    if (keyspaceDefinition != null) {
        return;
    }

    ImmutableMap.Builder<String, Object> strategyOptions = getKeySpaceProps();

    ImmutableMap<String, Object> options = ImmutableMap.<String, Object>builder()
            .put("strategy_class", fig.getStrategyClass()).put("strategy_options", strategyOptions.build())
            .build();

    keyspace.createKeyspace(options);

    strategyOptions.toString();

    logger.info("Created keyspace {} with options {}", keyspace.getKeyspaceName(), options.toString());

    waitForMigration();
}

From source file:org.apache.usergrid.locking.cassandra.AstyanaxLockManagerImpl.java

private void createLocksKeyspace() throws ConnectionException {

    ImmutableMap.Builder<String, Object> strategyOptions = getKeySpaceProps();

    ImmutableMap<String, Object> options = ImmutableMap.<String, Object>builder()
            .put("strategy_class", cassandraFig.getLocksKeyspaceStrategy())
            .put("strategy_options", strategyOptions.build()).build();

    keyspace.createKeyspaceIfNotExists(options);

    strategyOptions.toString();//w ww . java 2s . com

    logger.info("Keyspace {} created or already exists with options {}", keyspace.getKeyspaceName(),
            options.toString());
}

From source file:rapture.server.WatchRunner.java

@Override
public void run() {
    while (true) {
        WatchKey watchKey = null;
        try {//from ww  w. j a v  a2s. c o m
            watchKey = watchService.take();
            if (watchKey != null) {
                for (WatchEvent<?> watchEvent : watchKey.pollEvents()) {
                    if (watchEvent.kind() == OVERFLOW) {
                        log.error("Overflow event count: " + watchEvent.count());
                        continue;
                    }
                    // TODO: Add support to run scripts with an event.
                    // TODO: Check filepath is correct
                    String actionUri = getActionForEvent(this.dirPath, watchEvent.kind().name());
                    if (!actionUri.isEmpty()) {
                        String scheme = new RaptureURI(actionUri).getScheme().name();
                        log.debug("event created for path: " + this.dirPath);
                        ImmutableMap<String, String> params = ImmutableMap.of("filetoupload",
                                this.dirPath + watchEvent.context());

                        if (scheme.equals(Scheme.SCRIPT.name())) {
                            String runScript = Kernel.getScript().runScript(ContextFactory.getKernelUser(),
                                    actionUri, params);
                            log.info("Started script: " + runScript + " with params: " + params.toString());
                        }
                        if (scheme.equals(Scheme.WORKFLOW.name())) {
                            String createWorkOrder = Kernel.getDecision()
                                    .createWorkOrder(ContextFactory.getKernelUser(), actionUri, params);
                            log.info("Started workorder: " + createWorkOrder + " with params: "
                                    + params.toString());
                        }
                    } else {
                        log.debug("Event: " + watchEvent.kind().name() + " not set for directory: "
                                + this.dirPath);
                    }
                }
                watchKey.reset();
            }
        } catch (InterruptedException e) {
            log.error("Thread ID: " + Thread.currentThread().getId() + " interrupted!", e);
        }
    }
}

From source file:uk.ac.cam.cl.dtg.segue.api.InfoFacade.java

/**
 * Gets the current version of the segue application.
 * /*from  w  ww .ja v a2s . c o  m*/
 * @param request
 *            for caching
 * @return segue version as a string wrapped in a response.
 */
@GET
@Path("log_event_types")
@Produces(MediaType.APPLICATION_JSON)
public final Response getLogEventTypes(@Context final Request request) {
    ImmutableMap<String, Collection<String>> result;
    try {
        result = new ImmutableMap.Builder<String, Collection<String>>()
                .put("results", getLogManager().getAllEventTypes()).build();
    } catch (SegueDatabaseException e) {
        log.error("Database error has occurred", e);
        return new SegueErrorResponse(Status.INTERNAL_SERVER_ERROR, "A database error has occurred.")
                .toResponse();
    }

    EntityTag etag = new EntityTag(result.toString().hashCode() + "");
    Response cachedResponse = generateCachedResponse(request, etag, NUMBER_SECONDS_IN_ONE_DAY);
    if (cachedResponse != null) {
        return cachedResponse;
    }

    return Response.ok(result).tag(etag).cacheControl(this.getCacheControl(NUMBER_SECONDS_IN_ONE_DAY, false))
            .build();
}