示例#1
0
 @PUT
 @Path("blueprint/{name}")
 public Response updateBlueprint(
     @Context UriInfo uri, @PathParam("name") String oldName, ConfigManifest blueprint) {
   Response res;
   try {
     ZooKeeper zk = Controller.getInstance().getZKInstance();
     String newName = oldName;
     if (blueprint.getUrl() != null) {
       newName = ZookeeperUtil.getBaseURL(blueprint.getUrl().toString());
     } else {
       blueprint.setUrl(uri.getAbsolutePath().toURL());
     }
     byte[] data = JAXBUtil.write(blueprint);
     Stat stat =
         zk.exists(
             CommonConfigurationKeys.ZOOKEEPER_CONFIG_BLUEPRINT_PATH_DEFAULT + '/' + newName,
             false);
     if (stat != null && oldName.equals(newName)) {
       // Update existing blueprint
       String path =
           CommonConfigurationKeys.ZOOKEEPER_CONFIG_BLUEPRINT_PATH_DEFAULT + '/' + oldName;
       zk.delete(path, stat.getVersion());
       zk.create(
           CommonConfigurationKeys.ZOOKEEPER_CONFIG_BLUEPRINT_PATH_DEFAULT + '/' + newName,
           data,
           Ids.OPEN_ACL_UNSAFE,
           CreateMode.PERSISTENT);
     } else if (stat != null) {
       // Conflict in name change
       throw new WebApplicationException(409);
     } else {
       // Create new blueprint
       try {
         zk.create(
             CommonConfigurationKeys.ZOOKEEPER_CONFIG_BLUEPRINT_PATH_DEFAULT + '/' + newName,
             data,
             Ids.OPEN_ACL_UNSAFE,
             CreateMode.PERSISTENT);
       } catch (KeeperException.NodeExistsException e) {
         throw new WebApplicationException(409);
       }
     }
     res = Response.noContent().build();
     return res;
   } catch (WebApplicationException e) {
     throw e;
   } catch (Exception e) {
     LOG.error(ExceptionUtil.getStackTrace(e));
     throw new WebApplicationException(500);
   }
 }
示例#2
0
 @DELETE
 @Path("blueprint/{name}")
 public Response deleteStack(@PathParam("name") String name) {
   ZooKeeper zk = Controller.getInstance().getZKInstance();
   try {
     String path = ZookeeperUtil.getConfigManifestPath(name);
     Stat current = zk.exists(path, false);
     zk.delete(path, current.getVersion());
   } catch (Exception e) {
     LOG.error(ExceptionUtil.getStackTrace(e));
     throw new WebApplicationException(500);
   }
   Response res = Response.noContent().build();
   return res;
 }
示例#3
0
 @GET
 @Path("blueprint/{name}")
 public ConfigManifest getBlueprint(@PathParam("name") String name) {
   try {
     ZooKeeper zk = Controller.getInstance().getZKInstance();
     Stat current = new Stat();
     String path = ZookeeperUtil.getConfigManifestPath(name);
     byte[] data = zk.getData(path, false, current);
     ConfigManifest res = JAXBUtil.read(data, ConfigManifest.class);
     return res;
   } catch (Exception e) {
     LOG.error(ExceptionUtil.getStackTrace(e));
     throw new WebApplicationException(500);
   }
 }
示例#4
0
 @GET
 @Path("blueprint")
 public List<ConfigManifest> getList() {
   List<ConfigManifest> list = new ArrayList<ConfigManifest>();
   try {
     ZooKeeper zk = Controller.getInstance().getZKInstance();
     List<String> blueprints =
         zk.getChildren(CommonConfigurationKeys.ZOOKEEPER_CONFIG_BLUEPRINT_PATH_DEFAULT, false);
     Stat current = new Stat();
     for (String blueprint : blueprints) {
       byte[] data = zk.getData(ZookeeperUtil.getConfigManifestPath(blueprint), false, current);
       ConfigManifest x = JAXBUtil.read(data, ConfigManifest.class);
       list.add(x);
     }
   } catch (Exception e) {
     LOG.error(ExceptionUtil.getStackTrace(e));
     throw new WebApplicationException(500);
   }
   return list;
 }