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);
}
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);
}
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"));
}
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);
}
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);
}
Aggregations