Package org.vitaliyl.monitoring.server.rest

Source Code of org.vitaliyl.monitoring.server.rest.Root

package org.vitaliyl.monitoring.server.rest;

import java.util.ArrayList;
import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

import org.vitaliyl.monitoring.server.Datastore;
import org.vitaliyl.monitoring.server.beans.ListWrapper;
import org.vitaliyl.monitoring.server.beans.ServerDescriptor;
import org.vitaliyl.monitoring.server.dao.AServerDescriptorDAO;

import com.google.gson.Gson;

@Path("/servers")
@Produces("application/json")
public class Root {

  @GET
  public String getClichedMessage() {
    List<ServerDescriptor> list = AServerDescriptorDAO.getServerDescriptors();
    Gson gson = new Gson();
    return gson.toJson(new ListWrapper<ServerDescriptor>(list));
  }

  @GET
  @Path("/createServers")
  public String createServers() {
    List<ServerDescriptor> list = new ArrayList<ServerDescriptor>();

    ServerDescriptor descriptor;
    descriptor = new ServerDescriptor("http://iphone.releaze.dk/ngxstats", 600);
    list.add(descriptor);
    descriptor = new ServerDescriptor("http://campaigns.releaze.dk/ngxstats", 1800);
    list.add(descriptor);
    descriptor = new ServerDescriptor("http://tjek.releaze.dk/ngxstats", 600);
    list.add(descriptor);
    descriptor = new ServerDescriptor("http://nginx.releaze.dk/ngxstats", 600);
    list.add(descriptor);
    descriptor = new ServerDescriptor("http://src.releaze.dk/ngxstats", 1200);
    list.add(descriptor);
    descriptor = new ServerDescriptor("http://tjekscores.dk/ngxstats", 400);
    list.add(descriptor);
    descriptor = new ServerDescriptor("http://tjekbenzin.dk/ngxstats", 100);
    list.add(descriptor);
    descriptor = new ServerDescriptor("http://demo.releaze.dk/ngxstats", 100);
    list.add(descriptor);
    descriptor = new ServerDescriptor("http://util.releaze.dk/ngxstats", 200);
    list.add(descriptor);

    for (int i = 0; i < list.size(); i++) {
      AServerDescriptorDAO.createServerDescriptor(list.get(i));
    }
    Gson gson = new Gson();
    return gson.toJson(new ListWrapper<ServerDescriptor>(list));
  }

  @GET
  @Path("/all")
  public String deleteAll() {
    Datastore.deleteAllEntities(Datastore.SERVER_TYPE);
    return "{\"success\":true}";
  }

}
TOP

Related Classes of org.vitaliyl.monitoring.server.rest.Root

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.