Search in sources :

Example 1 with IdWorker

use of com.creditease.uav.helpers.uuid.IdWorker in project uavstack by uavorg.

the class ConfigurationManager method initNodeUUID.

private void initNodeUUID(String metadatafolder) {
    String idFile = metadatafolder + "/" + this.profileName + ".uuid";
    this.nodeUUID = IOHelper.readTxtFile(idFile, "utf-8");
    if (null == this.nodeUUID) {
        // read datacenter id, yes THINK BIG
        String datacenterid = this.getConfiguration("meta.datacenterid");
        if (null == datacenterid) {
            datacenterid = "1";
        }
        IdWorker idWorker = CommonHelper.getUUIDWorker(new Random().nextInt(30) + 1, Integer.parseInt(datacenterid));
        this.nodeUUID = String.valueOf(idWorker.nextId());
        try {
            IOHelper.writeTxtFile(idFile, this.nodeUUID, "utf-8", false);
        } catch (IOException e) {
            throw new RuntimeException("Write UUID to file \"" + idFile + "\" Fails.", e);
        }
    }
}
Also used : Random(java.util.Random) IdWorker(com.creditease.uav.helpers.uuid.IdWorker) IOException(java.io.IOException)

Example 2 with IdWorker

use of com.creditease.uav.helpers.uuid.IdWorker in project uavstack by uavorg.

the class GodEyeRestService method saveFeedback.

// ---------------------------------------新日志服务接口 END-------------------------------------
// ---------------------------------------反馈建议 START-----------------------------------
/**
 * searchNewLog
 *
 * @param data
 * @param resp
 */
@SuppressWarnings("unchecked")
@POST
@Path("/feedback/save")
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public void saveFeedback(String reqData, @Suspended AsyncResponse resp) {
    String userId = "";
    if (null != request.getSession(false)) {
        Object obj = request.getSession(false).getAttribute("apphub.gui.session.login.user.id");
        userId = null == obj ? "" : String.valueOf(obj);
    }
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
    String time = simpleDateFormat.format(new Date());
    Map<String, String> httpData = JSONHelper.toObject(reqData, Map.class);
    httpData.put("time", time);
    httpData.put("uid", userId);
    IdWorker idWorker = CommonHelper.getUUIDWorker(new Random().nextInt(30) + 1, 1);
    String uuid = String.valueOf(idWorker.nextId());
    httpData.put("key", uuid);
    /**
     * 打包请求数据
     */
    Map<String, Object> mapParam = new HashMap<String, Object>();
    mapParam.put("type", "create");
    mapParam.put("data", httpData);
    UAVHttpMessage request = new UAVHttpMessage();
    request.putRequest("mrd.data", JSONHelper.toString(mapParam));
    request.putRequest("datastore.name", "AppHub.feedback");
    request.putRequest("mgo.coll.name", "uav_feedback");
    doHttpPost("uav.app.manage.apphubmanager.http.addr", "/ah/feedback", request, new GodEyeCB(resp));
}
Also used : Random(java.util.Random) IdWorker(com.creditease.uav.helpers.uuid.IdWorker) HashMap(java.util.HashMap) UAVHttpMessage(com.creditease.agent.http.api.UAVHttpMessage) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Aggregations

IdWorker (com.creditease.uav.helpers.uuid.IdWorker)2 Random (java.util.Random)2 UAVHttpMessage (com.creditease.agent.http.api.UAVHttpMessage)1 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1