Search in sources :

Example 1 with AddCampaign

use of com.xrtb.commands.AddCampaign in project XRTB by benmfaul.

the class WebCampaign method startCampaign.

/**
	 * Starts the campaign from the web portal
	 * 
	 * @param cmd
	 *            Map. The JSON command structure from the web user.
	 * @return String. The JSON string of all the running campaigns in this
	 *         bidder.
	 */
public String startCampaign(Map cmd) throws Exception {
    Map response = new HashMap();
    try {
        String id = getString(cmd.get("id"));
        String name = (String) cmd.get("username");
        id = id.replaceAll("\"", "");
        Campaign c = db.getCampaign(name, id);
        Controller.getInstance().addCampaign(c);
        response.put("error", false);
        AddCampaign command = new AddCampaign(null, name, id);
        command.to = "*";
        command.from = Configuration.getInstance().instanceName;
        Controller.getInstance().sendLog(3, "WebAccess-Start-Campaign", "Campaign start: " + id);
    } catch (Exception error) {
        response.put("message", "failed: " + error.toString());
        response.put("error", true);
    }
    response.put("running", Configuration.getInstance().getLoadedCampaignNames());
    return getString(response);
}
Also used : AddCampaign(com.xrtb.commands.AddCampaign) Campaign(com.xrtb.common.Campaign) AddCampaign(com.xrtb.commands.AddCampaign) DeleteCampaign(com.xrtb.commands.DeleteCampaign) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with AddCampaign

use of com.xrtb.commands.AddCampaign in project XRTB by benmfaul.

the class Commands method loadInFromDatabase.

/**
  * Send a load from database file command.
  */
public void loadInFromDatabase() {
    System.out.print("Username in database to load:");
    String name = scan.nextLine();
    System.out.print("Campaign id in database to load:");
    String id = scan.nextLine();
    AddCampaign cmd = new AddCampaign("", name, id);
    cmd.from = uuid;
    commands.add(cmd);
}
Also used : AddCampaign(com.xrtb.commands.AddCampaign)

Example 3 with AddCampaign

use of com.xrtb.commands.AddCampaign in project XRTB by benmfaul.

the class TestZZZRedis method addCampaign.

/**
	 * Test adding a campaign
	 */
@Test
public void addCampaign() throws Exception {
    AddCampaign e = new AddCampaign("", "ben", "ben:payday");
    e.id = "ADDCAMP-ID";
    Thread.sleep(1000);
    rcv = null;
    latch = new CountDownLatch(1);
    commands.add(e);
    latch.await(5, TimeUnit.SECONDS);
    assertTrue(rcv.id.equals("ADDCAMP-ID"));
    assertTrue(rcv.status.equals("ok"));
}
Also used : AddCampaign(com.xrtb.commands.AddCampaign) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 4 with AddCampaign

use of com.xrtb.commands.AddCampaign in project XRTB by benmfaul.

the class WebCampaign method updateCampaign.

/**
	 * Updates a command in the database (NOT in the currently running list)
	 * 
	 * @param cmd
	 *            Map. The web user command map.
	 * @return String. JSON representation of the running campaigns.
	 */
public String updateCampaign(Map cmd) throws Exception {
    Map response = new HashMap();
    try {
        String name = (String) cmd.get("username");
        String id = getString(cmd.get("id"));
        id = id.replaceAll("\"", "");
        String data = (String) cmd.get("campaign");
        Campaign c = new Campaign(data);
        System.out.println(data);
        db.editCampaign(name, c);
        List<String> deletions = (List<String>) cmd.get("deletions");
        for (String s : deletions) {
            db.deleteCampaign(name, s);
        }
        dumpFile(cmd);
        if (Configuration.getInstance().isRunning(name, id)) {
            AddCampaign command = new AddCampaign(null, name, id);
            command.to = "*";
            command.from = Configuration.getInstance().instanceName;
        }
        c = db.getCampaign(name, id);
        Controller.getInstance().addCampaign(c);
        Controller.getInstance().sendLog(3, "WebAccess-Update-Campaign", name + " Modified campaign: " + id);
        Controller.getInstance().sendLog(3, "WebAccess-Start-Campaign", "Campaign start: " + id);
    } catch (Exception error) {
        error.printStackTrace();
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        error.printStackTrace(pw);
        response.put("message", "Incomplete construction, failed: " + sw.toString());
        response.put("error", true);
    }
    response.put("running", Configuration.getInstance().getLoadedCampaignNames());
    return getString(response);
}
Also used : AddCampaign(com.xrtb.commands.AddCampaign) Campaign(com.xrtb.common.Campaign) AddCampaign(com.xrtb.commands.AddCampaign) DeleteCampaign(com.xrtb.commands.DeleteCampaign) StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) PrintWriter(java.io.PrintWriter)

Example 5 with AddCampaign

use of com.xrtb.commands.AddCampaign in project XRTB by benmfaul.

the class Commands method startCampaign.

/**
  * Start a campaign (by loading into bidder memory
  */
public void startCampaign() {
    System.out.print("Which username:");
    String name = scan.nextLine();
    System.out.print("Which campaign to load from Aerospike:");
    String cname = scan.nextLine();
    System.out.print("Which bidder to load campaign into:");
    String to = scan.nextLine();
    AddCampaign cmd = new AddCampaign(to, name, cname);
    cmd.from = uuid;
    commands.add(cmd);
}
Also used : AddCampaign(com.xrtb.commands.AddCampaign)

Aggregations

AddCampaign (com.xrtb.commands.AddCampaign)5 DeleteCampaign (com.xrtb.commands.DeleteCampaign)2 Campaign (com.xrtb.common.Campaign)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.Test)1