Example usage for com.google.common.collect Multimap put

List of usage examples for com.google.common.collect Multimap put

Introduction

In this page you can find the example usage for com.google.common.collect Multimap put.

Prototype

boolean put(@Nullable K key, @Nullable V value);

Source Link

Document

Stores a key-value pair in this multimap.

Usage

From source file:org.jclouds.simpledb.samples.MainApp.java

public static void main(String[] args) throws IOException {

    // Args//from  ww w.j  ava 2s  .com
    String accesskeyid = args[0];
    String secretkey = args[1];
    Properties properties = new Properties();
    properties.setProperty("simpledb.identity", accesskeyid);
    properties.setProperty("simpledb.credential", secretkey);

    RestContext<SimpleDBClient, SimpleDBAsyncClient> context = new RestContextFactory().createContext(
            "simpledb", "AKIAJODKICBEKG7MM4XA", "FfqiNSiC88B6tJPDIOKUWUJGY68BQaQpkNz6Fsgq", new Properties());
    AttributePair p = new AttributePair("AccessNumber", "1213123", true);
    Multimap<String, AttributePair> m = LinkedHashMultimap.create();
    m.put("AccessNumber", p);
    Item attributes = new Item(m);

    // Use Provider API
    context.getApi().putAttributes(Region.EU_WEST_1, "tse", "AccessNumber", attributes);
    //context.getApi().createDomainInRegion(Region.EU_WEST_1, "tse");
    Map<String, Item> results = context.getApi().select(Region.EU_WEST_1, "select * from tse");
    System.out.println(results);
    ListDomainsOptions[] list = new ListDomainsOptions[100];
    //context.getApi().listDomainsInRegion(Region.EU_WEST_1, list);
    System.out.println(list[0]);
    context.close();
}

From source file:com.netflix.genie.client.sample.PigConfigServiceSampleClient.java

/**
 * Main for running client code./*from  ww w .jav  a  2s.c om*/
 */
public static void main(String[] args) throws Exception {

    // Initialize Eureka, if it is being used
    // System.out.println("Initializing Eureka");
    // PigConfigServiceClient.initEureka("test");

    System.out.println("Initializing list of Genie servers");
    ConfigurationManager.getConfigInstance().setProperty("genieClient.ribbon.listOfServers", "localhost:7001");

    System.out.println("Initializing PigConfigServiceClient");
    PigConfigServiceClient client = PigConfigServiceClient.getInstance();

    String userName = "genietest";
    String name = "MY_TEST_PIG_CONFIG";

    System.out.println("Creating new pig config");
    PigConfigElement pigConfigElement = new PigConfigElement();
    pigConfigElement.setUser(userName);
    pigConfigElement.setName(name);
    pigConfigElement.setType(Types.Configuration.TEST.name());
    pigConfigElement.setStatus(Types.ConfigStatus.INACTIVE.name());
    pigConfigElement.setS3PigProperties("s3://BUCKET/PATH/TO/PIG.PROPERTIES");
    pigConfigElement = client.createPigConfig(pigConfigElement);
    String id = pigConfigElement.getId();
    System.out.println("Pig config created with id: " + id);

    System.out.println("Getting pigConfigs using specified filter criteria");
    Multimap<String, String> params = ArrayListMultimap.create();
    params.put("name", name);
    params.put("limit", "3");
    PigConfigElement[] responses = client.getPigConfigs(params);
    for (PigConfigElement hce : responses) {
        System.out.println("Pig Configs: {id, status, updateTime} - {" + hce.getId() + ", " + hce.getStatus()
                + ", " + hce.getUpdateTime() + "}");
    }

    System.out.println("Getting pig config by id");
    pigConfigElement = client.getPigConfig(id);
    System.out.println("Pig config status: " + pigConfigElement.getStatus());

    System.out.println("Updating existing pig config");
    pigConfigElement.setStatus(Types.ConfigStatus.DEPRECATED.name());
    pigConfigElement = client.updatePigConfig(id, pigConfigElement);
    System.out.println("Updated status: " + pigConfigElement.getStatus() + " at time: "
            + pigConfigElement.getUpdateTime());

    System.out.println("Deleting pig config using id");
    pigConfigElement = client.deletePigConfig(id);
    System.out.println("Deleted pig config with id: " + pigConfigElement.getId());

    System.out.println("Done");
}

From source file:com.netflix.genie.client.sample.HiveConfigServiceSampleClient.java

/**
 * Main for running client code.//from   w  ww  .  j  a v a2s.  c  o m
 */
public static void main(String[] args) throws Exception {

    // Initialize Eureka, if it is being used
    // System.out.println("Initializing Eureka");
    // HiveConfigServiceClient.initEureka("test");

    System.out.println("Initializing list of Genie servers");
    ConfigurationManager.getConfigInstance().setProperty("genieClient.ribbon.listOfServers", "localhost:7001");

    System.out.println("Initializing HiveConfigServiceClient");
    HiveConfigServiceClient client = HiveConfigServiceClient.getInstance();

    String userName = "genietest";
    String name = "MY_TEST_HIVE_CONFIG";

    System.out.println("Creating new hive config");
    HiveConfigElement hiveConfigElement = new HiveConfigElement();
    hiveConfigElement.setUser(userName);
    hiveConfigElement.setName(name);
    hiveConfigElement.setType(Types.Configuration.TEST.name());
    hiveConfigElement.setStatus(Types.ConfigStatus.INACTIVE.name());
    hiveConfigElement.setS3HiveSiteXml("s3://BUCKET/PATH/TO/HIVE-SITE.XML");
    hiveConfigElement = client.createHiveConfig(hiveConfigElement);
    String id = hiveConfigElement.getId();
    System.out.println("Hive config created with id: " + id);

    System.out.println("Getting hiveConfigs using specified filter criteria");
    Multimap<String, String> params = ArrayListMultimap.create();
    params.put("name", name);
    params.put("limit", "3");
    HiveConfigElement[] responses = client.getHiveConfigs(params);
    for (HiveConfigElement hce : responses) {
        System.out.println("Hive Configs: {id, status, updateTime} - {" + hce.getId() + ", " + hce.getStatus()
                + ", " + hce.getUpdateTime() + "}");
    }

    System.out.println("Getting hive config by id");
    hiveConfigElement = client.getHiveConfig(id);
    System.out.println("Hive config status: " + hiveConfigElement.getStatus());

    System.out.println("Updating existing hive config");
    hiveConfigElement.setStatus(Types.ConfigStatus.DEPRECATED.name());
    hiveConfigElement = client.updateHiveConfig(id, hiveConfigElement);
    System.out.println("Updated status: " + hiveConfigElement.getStatus() + " at time: "
            + hiveConfigElement.getUpdateTime());

    System.out.println("Deleting hive config using id");
    hiveConfigElement = client.deleteHiveConfig(id);
    System.out.println("Deleted hive config with id: " + hiveConfigElement.getId());

    System.out.println("Done");
}

From source file:com.netflix.genie.client.sample.ClusterConfigServiceSampleClient.java

/**
 * Main for running client code./*from   w ww  .j a  v a 2 s  . c o m*/
 */
public static void main(String[] args) throws Exception {

    // Initialize Eureka, if it is being used
    // System.out.println("Initializing Eureka");
    // ClusterConfigServiceClient.initEureka("test");

    System.out.println("Initializing list of Genie servers");
    ConfigurationManager.getConfigInstance().setProperty("genieClient.ribbon.listOfServers", "localhost:7001");

    System.out.println("Initializing ClusterConfigServiceClient");
    ClusterConfigServiceClient client = ClusterConfigServiceClient.getInstance();

    String userName = "genietest";
    String name = "MY_TEST_CLUSTER_CONFIG";

    System.out.println("Creating new hive config for cluster");
    HiveConfigElement hiveConfigElement = new HiveConfigElement();
    hiveConfigElement.setUser(userName);
    String hiveConfigName = "MY_TEST_HIVE_CONFIG";
    hiveConfigElement.setName(hiveConfigName);
    hiveConfigElement.setType(Types.Configuration.TEST.name());
    hiveConfigElement.setStatus(Types.ConfigStatus.INACTIVE.name());
    hiveConfigElement.setS3HiveSiteXml("s3://BUCKET/PATH/TO/HIVE-SITE.XML");
    HiveConfigServiceClient hiveConfigClient = HiveConfigServiceClient.getInstance();
    hiveConfigElement = hiveConfigClient.createHiveConfig(hiveConfigElement);
    String hiveConfigId = hiveConfigElement.getId();
    System.out.println("Hive config created with id: " + hiveConfigId);

    System.out.println("Creating new cluster config");
    ClusterConfigElement clusterConfigElement = new ClusterConfigElement();
    clusterConfigElement.setUser(userName);
    clusterConfigElement.setName(name);
    clusterConfigElement.setTest(Boolean.TRUE);
    clusterConfigElement.setAdHoc(Boolean.FALSE);
    clusterConfigElement.setStatus(Types.ClusterStatus.OUT_OF_SERVICE.name());
    clusterConfigElement.setS3MapredSiteXml("s3://PATH/TO/MAPRED-SITE.XML");
    clusterConfigElement.setS3HdfsSiteXml("s3://PATH/TO/HDFS-SITE.XML");
    clusterConfigElement.setS3CoreSiteXml("s3://PATH/TO/CORE-SITE.XML");
    clusterConfigElement.setTestHiveConfigId(hiveConfigId);

    clusterConfigElement = client.createClusterConfig(clusterConfigElement);
    String id = clusterConfigElement.getId();
    System.out.println("Cluster config created with id: " + id);

    System.out.println("Getting clusterConfigs using specified filter criteria");
    Multimap<String, String> params = ArrayListMultimap.create();
    params.put("name", name);
    params.put("adHoc", "false");
    params.put("test", "true");
    params.put("limit", "3");
    ClusterConfigElement[] responses = client.getClusterConfigs(params);
    for (ClusterConfigElement hce : responses) {
        System.out.println("Cluster Configs: {id, status, updateTime} - {" + hce.getId() + ", "
                + hce.getStatus() + ", " + hce.getUpdateTime() + "}");
    }

    System.out.println("Getting cluster config by id");
    clusterConfigElement = client.getClusterConfig(id);
    System.out.println("Cluster config status: " + clusterConfigElement.getStatus());

    System.out.println("Updating existing cluster config");
    clusterConfigElement.setStatus(Types.ClusterStatus.TERMINATED.name());
    clusterConfigElement = client.updateClusterConfig(id, clusterConfigElement);
    System.out.println("Updated status: " + clusterConfigElement.getStatus() + " at time: "
            + clusterConfigElement.getUpdateTime());

    System.out.println("Deleting cluster config using id");
    clusterConfigElement = client.deleteClusterConfig(id);
    System.out.println("Deleted cluster config with id: " + clusterConfigElement.getId());

    System.out.println("Deleting hive config using id");
    hiveConfigElement = hiveConfigClient.deleteHiveConfig(hiveConfigId);
    System.out.println("Deleted hive config with id: " + hiveConfigElement.getId());

    System.out.println("Done");
}

From source file:com.netflix.genie.client.sample.ExecutionServiceSampleClient.java

/**
 * Main for running client code ./*from   ww w . j  av a2s  . co  m*/
 *
 * @param args command line arguments
 * @throws Exception On any issue.
 */
public static void main(final String[] args) throws Exception {

    // Initialize Eureka, if it is being used
    // LOG.info("Initializing Eureka");
    // ExecutionServiceClient.initEureka("test");
    LOG.info("Initializing list of Genie servers");
    ConfigurationManager.getConfigInstance().setProperty("genie2Client.ribbon.listOfServers",
            "http://localhost:7001");

    LOG.info("Initializing ExecutionServiceClient");
    final ExecutionServiceClient client = ExecutionServiceClient.getInstance();

    final String userName = "genietest";
    final String jobName = "sampleClientTestJob";
    LOG.info("Getting jobs using specified filter criteria");
    final Multimap<String, String> params = ArrayListMultimap.create();
    params.put("userName", userName);
    params.put("status", JobStatus.FAILED.name());
    params.put("limit", "3");
    for (final Job ji : client.getJobs(params)) {
        LOG.info("Job: {id, status, finishTime} - {" + ji.getId() + ", " + ji.getStatus() + ", "
                + ji.getFinished() + "}");
    }

    LOG.info("Running Hive job");
    final Set<String> criteriaTags = new HashSet<>();
    criteriaTags.add("adhoc");
    final ClusterCriteria criteria = new ClusterCriteria(criteriaTags);
    final List<ClusterCriteria> clusterCriterias = new ArrayList<>();
    final Set<String> commandCriteria = new HashSet<>();
    clusterCriterias.add(criteria);
    commandCriteria.add("hive");

    Job job = new Job(userName, jobName, "1.0", "-f hive.q", commandCriteria, clusterCriterias);

    job.setDescription("This is a test");

    // Add some tags for metadata about the job. This really helps for reporting on
    // the jobs and categorization.
    final Set<String> jobTags = new HashSet<>();
    jobTags.add("testgenie");
    jobTags.add("sample");

    job.setTags(jobTags);

    // send the query as an attachment
    final Set<FileAttachment> attachments = new HashSet<>();
    final FileAttachment attachment = new FileAttachment();
    attachment.setName("hive.q");
    attachment.setData("select count(*) from counters where dateint=20120430 and hour=10;".getBytes("UTF-8"));

    attachments.add(attachment);
    job.setAttachments(attachments);
    job = client.submitJob(job);

    final String jobID = job.getId();
    final String outputURI = job.getOutputURI();
    LOG.info("Job ID: " + jobID);
    LOG.info("Output URL: " + outputURI);

    LOG.info("Getting jobInfo by jobID");
    job = client.getJob(jobID);
    LOG.info(job.toString());

    LOG.info("Waiting for job to finish");
    final int blockTimeout = 600000;
    final int pollTime = 5000;
    job = client.waitForCompletion(jobID, blockTimeout, pollTime);
    LOG.info("Job status: " + job.getStatus());

    LOG.info("Killing jobs using jobID");
    final Job killedJob = client.killJob(jobID);
    LOG.info("Job status: " + killedJob.getStatus());

    LOG.info("Done");
}

From source file:com.github.rinde.vanlon15prima.PerformExperiment.java

public static void main(String[] args) {
    final long time = System.currentTimeMillis();
    final Experiment.Builder experimentBuilder = Experiment.build(SUM).computeLocal().withRandomSeed(123)
            .withThreads(Runtime.getRuntime().availableProcessors()).repeat(1)
            .addScenarios(FileProvider.builder().add(Paths.get(DATASET)).filter("glob:**[09].scen"))
            .addResultListener(new CommandLineProgress(System.out))
            .usePostProcessor(PostProcessors.statisticsPostProcessor())
            // central: cheapest insertion configuration
            .addConfiguration(//from w  ww . ja v a 2  s  . c om
                    Central.solverConfiguration(CheapestInsertionHeuristic.supplier(SUM), "CheapInsert"))
            // central: random
            .addConfiguration(Central.solverConfiguration(RandomSolver.supplier()))
            // mas: auction cheapest insertion with 2-opt per vehicle
            .addConfiguration(MASConfiguration.pdptwBuilder().setName("Auction-R-opt2cih-B-cih")
                    .addEventHandler(AddVehicleEvent.class, new VehicleHandler(
                            SolverRoutePlanner.supplier(
                                    Opt2.breadthFirstSupplier(CheapestInsertionHeuristic.supplier(SUM), SUM)),
                            SolverBidder.supplier(SUM, CheapestInsertionHeuristic.supplier(SUM))))
                    .addModel(SolverModel.builder()).addModel(AuctionCommModel.builder()).build());

    final Optional<ExperimentResults> results = experimentBuilder.perform(System.out, args);
    final long duration = System.currentTimeMillis() - time;
    if (!results.isPresent()) {
        return;
    }

    System.out.println("Done, computed " + results.get().getResults().size() + " simulations in "
            + duration / 1000d + "s");

    final Multimap<MASConfiguration, SimulationResult> groupedResults = LinkedHashMultimap.create();
    for (final SimulationResult sr : results.get().sortedResults()) {
        groupedResults.put(sr.getSimArgs().getMasConfig(), sr);
    }

    for (final MASConfiguration config : groupedResults.keySet()) {
        final Collection<SimulationResult> group = groupedResults.get(config);

        final File configResult = new File(RESULTS + config.getName() + ".csv");
        try {
            Files.createParentDirs(configResult);
        } catch (final IOException e1) {
            throw new IllegalStateException(e1);
        }
        // deletes the file in case it already exists
        configResult.delete();
        try {
            Files.append(
                    "dynamism,urgency,scale,cost,travel_time,tardiness,over_time,is_valid,scenario_id,random_seed,comp_time,num_vehicles,num_orders\n",
                    configResult, Charsets.UTF_8);
        } catch (final IOException e1) {
            throw new IllegalStateException(e1);
        }

        for (final SimulationResult sr : group) {
            final String pc = sr.getSimArgs().getScenario().getProblemClass().getId();
            final String id = sr.getSimArgs().getScenario().getProblemInstanceId();
            final int numVehicles = FluentIterable.from(sr.getSimArgs().getScenario().getEvents())
                    .filter(AddVehicleEvent.class).size();
            try {
                final String scenarioName = Joiner.on("-").join(pc, id);
                final List<String> propsStrings = Files
                        .readLines(new File(DATASET + scenarioName + ".properties"), Charsets.UTF_8);
                final Map<String, String> properties = Splitter.on("\n").withKeyValueSeparator(" = ")
                        .split(Joiner.on("\n").join(propsStrings));

                final double dynamism = Double.parseDouble(properties.get("dynamism_bin"));
                final long urgencyMean = Long.parseLong(properties.get("urgency"));
                final double scale = Double.parseDouble(properties.get("scale"));

                final StatisticsDTO stats = (StatisticsDTO) sr.getResultObject();
                final double cost = SUM.computeCost(stats);
                final double travelTime = SUM.travelTime(stats);
                final double tardiness = SUM.tardiness(stats);
                final double overTime = SUM.overTime(stats);
                final boolean isValidResult = SUM.isValidResult(stats);
                final long computationTime = stats.computationTime;

                final long numOrders = Long.parseLong(properties.get("AddParcelEvent"));

                final String line = Joiner.on(",")
                        .appendTo(new StringBuilder(),
                                asList(dynamism, urgencyMean, scale, cost, travelTime, tardiness, overTime,
                                        isValidResult, scenarioName, sr.getSimArgs().getRandomSeed(),
                                        computationTime, numVehicles, numOrders))
                        .append(System.lineSeparator()).toString();
                if (!isValidResult) {
                    System.err.println("WARNING: FOUND AN INVALID RESULT: ");
                    System.err.println(line);
                }
                Files.append(line, configResult, Charsets.UTF_8);
            } catch (final IOException e) {
                throw new IllegalStateException(e);
            }
        }
    }
}

From source file:com.netflix.genie.client.sample.CommandServiceSampleClient.java

/**
 * Main for running client code.// www.j av a 2  s .c o  m
 *
 * @param args program arguments
 * @throws Exception on issue.
 */
public static void main(final String[] args) throws Exception {

    // Initialize Eureka, if it is being used
    // LOG.info("Initializing Eureka");
    // ApplicationServiceClient.initEureka("test");
    LOG.info("Initializing list of Genie servers");
    ConfigurationManager.getConfigInstance().setProperty("genie2Client.ribbon.listOfServers", "localhost:7001");

    LOG.info("Initializing ApplicationServiceClient");
    final ApplicationServiceClient appClient = ApplicationServiceClient.getInstance();

    final Application app1 = appClient.createApplication(
            ApplicationServiceSampleClient.getSampleApplication(ApplicationServiceSampleClient.ID));
    LOG.info("Created application:");
    LOG.info(app1.toString());

    final Application app2 = appClient.createApplication(
            ApplicationServiceSampleClient.getSampleApplication(ApplicationServiceSampleClient.ID + "2"));
    LOG.info("Created application:");
    LOG.info(app2.toString());
    LOG.info("Initializing CommandServiceClient");
    final CommandServiceClient commandClient = CommandServiceClient.getInstance();

    LOG.info("Creating command pig13_mr2");
    final Command command1 = commandClient.createCommand(createSampleCommand(ID));
    commandClient.setApplicationForCommand(command1.getId(), app1);
    LOG.info("Created command:");
    LOG.info(command1.toString());

    LOG.info("Getting Commands using specified filter criteria name =  " + CMD_NAME);
    final Multimap<String, String> params = ArrayListMultimap.create();
    params.put("name", CMD_NAME);
    final List<Command> commands = commandClient.getCommands(params);
    if (commands.isEmpty()) {
        LOG.info("No commands found for specified criteria.");
    } else {
        LOG.info("Commands found:");
        for (final Command command : commands) {
            LOG.info(command.toString());
        }
    }

    LOG.info("Getting command config by id");
    final Command command3 = commandClient.getCommand(ID);
    LOG.info(command3.toString());

    LOG.info("Updating existing command config");
    command3.setStatus(CommandStatus.INACTIVE);
    final Command command4 = commandClient.updateCommand(ID, command3);
    LOG.info(command4.toString());

    LOG.info("Configurations for command with id " + command1.getId());
    final Set<String> configs = commandClient.getConfigsForCommand(command1.getId());
    for (final String config : configs) {
        LOG.info("Config = " + config);
    }

    LOG.info("Adding configurations to command with id " + command1.getId());
    final Set<String> newConfigs = new HashSet<>();
    newConfigs.add("someNewConfigFile");
    newConfigs.add("someOtherNewConfigFile");
    final Set<String> configs2 = commandClient.addConfigsToCommand(command1.getId(), newConfigs);
    for (final String config : configs2) {
        LOG.info("Config = " + config);
    }

    LOG.info("Updating set of configuration files associated with id " + command1.getId());
    //This should remove the original config leaving only the two in this set
    final Set<String> configs3 = commandClient.updateConfigsForCommand(command1.getId(), newConfigs);
    for (final String config : configs3) {
        LOG.info("Config = " + config);
    }

    LOG.info("Deleting all the configuration files from the command with id " + command1.getId());
    //This should remove the original config leaving only the two in this set
    final Set<String> configs4 = commandClient.removeAllConfigsForCommand(command1.getId());
    for (final String config : configs4) {
        //Shouldn't print anything
        LOG.info("Config = " + config);
    }

    /**************** Begin tests for tag Api's *********************/
    LOG.info("Get tags for command with id " + command1.getId());
    final Set<String> tags = command1.getTags();
    for (final String tag : tags) {
        LOG.info("Tag = " + tag);
    }

    LOG.info("Adding tags to command with id " + command1.getId());
    final Set<String> newTags = new HashSet<>();
    newTags.add("tag1");
    newTags.add("tag2");
    final Set<String> tags2 = commandClient.addTagsToCommand(command1.getId(), newTags);
    for (final String tag : tags2) {
        LOG.info("Tag = " + tag);
    }

    LOG.info("Updating set of tags associated with id " + command1.getId());
    //This should remove the original config leaving only the two in this set
    final Set<String> tags3 = commandClient.updateTagsForCommand(command1.getId(), newTags);
    for (final String tag : tags3) {
        LOG.info("Tag = " + tag);
    }

    LOG.info("Deleting one tag from the command with id " + command1.getId());
    //This should remove the "tag3" from the tags
    final Set<String> tags5 = commandClient.removeTagForCommand(command1.getId(), "tag1");
    for (final String tag : tags5) {
        //Shouldn't print anything
        LOG.info("Tag = " + tag);
    }

    LOG.info("Deleting all the tags from the command with id " + command1.getId());
    //This should remove the original config leaving only the two in this set
    final Set<String> tags4 = commandClient.removeAllConfigsForCommand(command1.getId());
    for (final String tag : tags4) {
        //Shouldn't print anything
        LOG.info("Config = " + tag);
    }
    /********************** End tests for tag Api's **********************/

    LOG.info("Application for command with id " + command1.getId());
    final Application application = commandClient.getApplicationForCommand(command1.getId());
    LOG.info("Application = " + application);

    LOG.info("Removing Application for command with id " + command1.getId());
    final Application application2 = commandClient.removeApplicationForCommand(command1.getId());
    LOG.info("Application = " + application2);

    LOG.info("Getting all the clusters for command with id  " + command1.getId());
    final Set<Cluster> clusters = commandClient.getClustersForCommand(command1.getId());
    for (final Cluster cluster : clusters) {
        LOG.info("Cluster = " + cluster);
    }

    LOG.info("Deleting command config using id");
    final Command command5 = commandClient.deleteCommand(ID);
    LOG.info("Deleted command config with id: " + ID);
    LOG.info(command5.toString());

    LOG.info("Deleting all applications");
    final List<Application> deletedApps = appClient.deleteAllApplications();
    LOG.info("Deleted all applications");
    LOG.info(deletedApps.toString());

    LOG.info("Done");
}

From source file:com.netflix.genie.client.sample.ApplicationServiceSampleClient.java

/**
 * Main for running client code./*  w ww . ja v  a  2  s. co  m*/
 *
 * @param args program arguments
 * @throws Exception On issue.
 */
public static void main(final String[] args) throws Exception {

    //        //Initialize Eureka, if it is being used
    //        LOG.info("Initializing Eureka");
    //        ApplicationServiceClient.initEureka("test");

    LOG.info("Initializing list of Genie servers");
    ConfigurationManager.getConfigInstance().setProperty("genie2Client.ribbon.listOfServers", "localhost:7001");

    LOG.info("Initializing ApplicationServiceClient");
    final ApplicationServiceClient appClient = ApplicationServiceClient.getInstance();

    LOG.info("Creating new application config");
    final Application app1 = appClient.createApplication(getSampleApplication(null));
    LOG.info("Application configuration created with id: " + app1.getId());
    LOG.info(app1.toString());

    LOG.info("Getting Applications using specified filter criteria name =  " + APP_NAME);
    final Multimap<String, String> params = ArrayListMultimap.create();
    params.put("name", APP_NAME);
    final List<Application> appResponses = appClient.getApplications(params);
    if (appResponses.isEmpty()) {
        LOG.info("No applications found for specified criteria.");
    } else {
        LOG.info("Applications found:");
        for (final Application appResponse : appResponses) {
            LOG.info(appResponse.toString());
        }
    }

    LOG.info("Getting application config by id");
    final Application app2 = appClient.getApplication(app1.getId());
    LOG.info(app2.toString());

    LOG.info("Updating existing application config");
    app2.setStatus(ApplicationStatus.INACTIVE);
    final Application app3 = appClient.updateApplication(app1.getId(), app2);
    LOG.info(app3.toString());

    LOG.info("Configurations for application with id " + app1.getId());
    final Set<String> configs = appClient.getConfigsForApplication(app1.getId());
    for (final String config : configs) {
        LOG.info("Config = " + config);
    }

    LOG.info("Adding configurations to application with id " + app1.getId());
    final Set<String> newConfigs = new HashSet<>();
    newConfigs.add("someNewConfigFile");
    newConfigs.add("someOtherNewConfigFile");
    final Set<String> configs2 = appClient.addConfigsToApplication(app1.getId(), newConfigs);
    for (final String config : configs2) {
        LOG.info("Config = " + config);
    }

    LOG.info("Updating set of configuration files associated with id " + app1.getId());
    //This should remove the original config leaving only the two in this set
    final Set<String> configs3 = appClient.updateConfigsForApplication(app1.getId(), newConfigs);
    for (final String config : configs3) {
        LOG.info("Config = " + config);
    }

    LOG.info("Deleting all the configuration files from the application with id " + app1.getId());
    //This should remove the original config leaving only the two in this set
    final Set<String> configs4 = appClient.removeAllConfigsForApplication(app1.getId());
    for (final String config : configs4) {
        //Shouldn't print anything
        LOG.info("Config = " + config);
    }

    /**************** Begin tests for tag Api's *********************/
    LOG.info("Get tags for application with id " + app1.getId());
    final Set<String> tags = app1.getTags();
    for (final String tag : tags) {
        LOG.info("Tag = " + tag);
    }

    LOG.info("Adding tags to application with id " + app1.getId());
    final Set<String> newTags = new HashSet<>();
    newTags.add("tag1");
    newTags.add("tag2");
    final Set<String> tags2 = appClient.addTagsToApplication(app1.getId(), newTags);
    for (final String tag : tags2) {
        LOG.info("Tag = " + tag);
    }

    LOG.info("Updating set of tags associated with id " + app1.getId());
    //This should remove the original config leaving only the two in this set
    final Set<String> tags3 = appClient.updateTagsForApplication(app1.getId(), newTags);
    for (final String tag : tags3) {
        LOG.info("Tag = " + tag);
    }

    LOG.info("Deleting one tag from the application with id " + app1.getId());
    //This should remove the "tag3" from the tags
    final Set<String> tags5 = appClient.removeTagForApplication(app1.getId(), "tag1");
    for (final String tag : tags5) {
        //Shouldn't print anything
        LOG.info("Tag = " + tag);
    }

    LOG.info("Deleting all the tags from the application with id " + app1.getId());
    //This should remove the original config leaving only the two in this set
    final Set<String> tags4 = appClient.removeAllConfigsForApplication(app1.getId());
    for (final String tag : tags4) {
        //Shouldn't print anything
        LOG.info("Config = " + tag);
    }
    /********************** End tests for tag Api's **********************/

    LOG.info("Jars for application with id " + app1.getId());
    final Set<String> jars = appClient.getJarsForApplication(app1.getId());
    for (final String jar : jars) {
        LOG.info("jar = " + jar);
    }

    LOG.info("Adding jars to application with id " + app1.getId());
    final Set<String> newJars = new HashSet<>();
    newJars.add("someNewJarFile.jar");
    newJars.add("someOtherNewJarFile.jar");
    final Set<String> jars2 = appClient.addJarsToApplication(app1.getId(), newJars);
    for (final String jar : jars2) {
        LOG.info("jar = " + jar);
    }

    LOG.info("Updating set of jars associated with id " + app1.getId());
    //This should remove the original jar leaving only the two in this set
    final Set<String> jars3 = appClient.updateJarsForApplication(app1.getId(), newJars);
    for (final String jar : jars3) {
        LOG.info("jar = " + jar);
    }

    LOG.info("Deleting all the jars from the application with id " + app1.getId());
    //This should remove the original jar leaving only the two in this set
    final Set<String> jars4 = appClient.removeAllJarsForApplication(app1.getId());
    for (final String jar : jars4) {
        //Shouldn't print anything
        LOG.info("jar = " + jar);
    }

    LOG.info("Getting the commands associated with id " + app1.getId());
    final Set<Command> commands = appClient.getCommandsForApplication(app1.getId());
    for (final Command command : commands) {
        LOG.info("Command: " + command.toString());
    }

    LOG.info("Deleting application using id");
    final Application app4 = appClient.deleteApplication(app1.getId());
    LOG.info("Deleted application with id: " + app4.getId());
    LOG.info(app4.toString());

    LOG.info("Done");
}

From source file:com.github.rinde.dynurg.Experimentation.java

public static void main(String[] args) {
    System.out.println(System.getProperty("jppf.config"));

    final long time = System.currentTimeMillis();
    final Experiment.Builder experimentBuilder = Experiment.build(SUM).computeDistributed().withRandomSeed(123)
            .repeat(10).numBatches(10)/*from  ww  w  .j a  v a 2  s  .  co  m*/
            .addScenarios(
                    FileProvider.builder().add(Paths.get(DATASET)).filter("glob:**[01].[0-9]0#[0-5].scen"))
            .addResultListener(new CommandLineProgress(System.out))
            .addConfiguration(
                    Central.solverConfiguration(CheapestInsertionHeuristic.supplier(SUM), "-CheapInsert"))
            .addConfiguration(Central.solverConfiguration(CheapestInsertionHeuristic.supplier(TARDINESS),
                    "-CheapInsert-Tard"))
            .addConfiguration(Central.solverConfiguration(CheapestInsertionHeuristic.supplier(DISTANCE),
                    "-CheapInsert-Dist"))
            .addConfiguration(Central.solverConfiguration(
                    Opt2.breadthFirstSupplier(CheapestInsertionHeuristic.supplier(SUM), SUM),
                    "-bfsOpt2-CheapInsert"))
            .addConfiguration(Central.solverConfiguration(
                    Opt2.breadthFirstSupplier(CheapestInsertionHeuristic.supplier(TARDINESS), TARDINESS),
                    "-bfsOpt2-CheapInsert-Tard"))
            .addConfiguration(Central.solverConfiguration(
                    Opt2.breadthFirstSupplier(CheapestInsertionHeuristic.supplier(DISTANCE), DISTANCE),
                    "-bfsOpt2-CheapInsert-Dist"))
            .addConfiguration(Central.solverConfiguration(
                    Opt2.depthFirstSupplier(CheapestInsertionHeuristic.supplier(SUM), SUM),
                    "-dfsOpt2-CheapInsert"))
            .addConfiguration(Central.solverConfiguration(
                    Opt2.depthFirstSupplier(CheapestInsertionHeuristic.supplier(TARDINESS), TARDINESS),
                    "-dfsOpt2-CheapInsert-Tard"))
            .addConfiguration(Central.solverConfiguration(
                    Opt2.depthFirstSupplier(CheapestInsertionHeuristic.supplier(DISTANCE), DISTANCE),
                    "-dfsOpt2-CheapInsert-Dist"));

    final Menu m = ExperimentCli.createMenuBuilder(experimentBuilder)
            .add(Option.builder("nv", ArgumentParser.INTEGER).longName("number-of-vehicles")
                    .description("Changes the number of vehicles in all scenarios.").build(), experimentBuilder,
                    new ArgHandler<Experiment.Builder, Integer>() {
                        @Override
                        public void execute(Experiment.Builder subject, Optional<Integer> argument) {
                            subject.setScenarioReader(new NumVehiclesScenarioParser(argument.get()));
                        }
                    })
            .build();

    final Optional<String> error = m.safeExecute(args);
    if (error.isPresent()) {
        System.err.println(error.get());
        return;
    }
    final ExperimentResults results = experimentBuilder.perform();

    final long duration = System.currentTimeMillis() - time;
    System.out
            .println("Done, computed " + results.results.size() + " simulations in " + duration / 1000d + "s");

    final Multimap<MASConfiguration, SimulationResult> groupedResults = LinkedHashMultimap.create();
    for (final SimulationResult sr : results.sortedResults()) {
        groupedResults.put(sr.masConfiguration, sr);
    }

    for (final MASConfiguration config : groupedResults.keySet()) {
        final Collection<SimulationResult> group = groupedResults.get(config);

        final File configResult = new File(RESULTS + config.toString() + ".csv");
        try {
            Files.createParentDirs(configResult);
        } catch (final IOException e1) {
            throw new IllegalStateException(e1);
        }
        // deletes the file in case it already exists
        configResult.delete();
        try {
            Files.append(
                    "dynamism,urgency_mean,urgency_sd,cost,travel_time,tardiness,over_time,is_valid,scenario_id,random_seed,comp_time,num_vehicles\n",
                    configResult, Charsets.UTF_8);
        } catch (final IOException e1) {
            throw new IllegalStateException(e1);
        }

        for (final SimulationResult sr : group) {
            final String pc = sr.scenario.getProblemClass().getId();
            final String id = sr.scenario.getProblemInstanceId();
            final int numVehicles = FluentIterable.from(sr.scenario.asList()).filter(AddVehicleEvent.class)
                    .size();
            try {
                final List<String> propsStrings = Files
                        .readLines(new File("files/dataset/" + pc + id + ".properties"), Charsets.UTF_8);
                final Map<String, String> properties = Splitter.on("\n").withKeyValueSeparator(" = ")
                        .split(Joiner.on("\n").join(propsStrings));

                final double dynamism = Double.parseDouble(properties.get("dynamism"));
                final double urgencyMean = Double.parseDouble(properties.get("urgency_mean"));
                final double urgencySd = Double.parseDouble(properties.get("urgency_sd"));

                final double cost = SUM.computeCost(sr.stats);
                final double travelTime = SUM.travelTime(sr.stats);
                final double tardiness = SUM.tardiness(sr.stats);
                final double overTime = SUM.overTime(sr.stats);
                final boolean isValidResult = SUM.isValidResult(sr.stats);
                final long computationTime = sr.stats.computationTime;

                final String line = Joiner.on(",")
                        .appendTo(new StringBuilder(),
                                asList(dynamism, urgencyMean, urgencySd, cost, travelTime, tardiness, overTime,
                                        isValidResult, pc + id, sr.seed, computationTime, numVehicles))
                        .append(System.lineSeparator()).toString();
                if (!isValidResult) {
                    System.err.println("WARNING: FOUND AN INVALID RESULT: ");
                    System.err.println(line);
                }
                Files.append(line, configResult, Charsets.UTF_8);
            } catch (final IOException e) {
                throw new IllegalStateException(e);
            }
        }
    }
}

From source file:PCC.java

/**
 * @param args the command line arguments
 * @throws java.io.IOException//  ww  w.  j av a2s.  c o  m
 */

public static void main(String[] args) throws IOException {
    // TODO code application logic here

    PearsonsCorrelation corel = new PearsonsCorrelation();
    PCC method = new PCC();
    ArrayList<String> name = new ArrayList<>();
    Multimap<String, String> genes = ArrayListMultimap.create();
    BufferedWriter bw = new BufferedWriter(new FileWriter(args[1]));
    BufferedReader br = new BufferedReader(new FileReader(args[0]));
    String str;
    while ((str = br.readLine()) != null) {
        String[] a = str.split("\t");
        name.add(a[0]);
        for (int i = 1; i < a.length; i++) {
            genes.put(a[0], a[i]);
        }
    }
    for (String key : genes.keySet()) {
        double[] first = new double[genes.get(key).size()];
        int element1 = 0;
        for (String value : genes.get(key)) {
            double d = Double.parseDouble(value);
            first[element1] = d;
            element1++;
        }
        for (String key1 : genes.keySet()) {
            if (!key.equals(key1)) {
                double[] second = new double[genes.get(key1).size()];
                int element2 = 0;
                for (String value : genes.get(key1)) {
                    double d = Double.parseDouble(value);
                    second[element2] = d;
                    element2++;

                }
                double corrlation = corel.correlation(first, second);
                if (corrlation > 0.5) {
                    bw.write(key + "\t" + key1 + "\t" + corrlation + "\t"
                            + method.pvalue(corrlation, second.length) + "\n");
                }
            }
        }
    }
    br.close();
    bw.close();
}