Package com.cloudera.lib.service

Examples of com.cloudera.lib.service.Instrumentation$Variable


        Groups groups = HoopServer.get().get(Groups.class);
        List<String> userGroups = groups.getGroups(user.getName());
        if (!userGroups.contains(HoopServer.get().getAdminGroup())) {
          throw new AccessControlException("User not in Hoop admin group");
        }
        Instrumentation instrumentation = HoopServer.get().get(Instrumentation.class);
        Map snapshot = instrumentation.getSnapshot();
        response = Response.ok(snapshot).build();
        break;
      }
    }
    return response;
View Full Code Here


  }

  @Override
  public void postInit() throws ServiceException {
    super.postInit();
    Instrumentation instrumentation = getServer().get(Instrumentation.class);
    instrumentation.addVariable(INSTRUMENTATION_GROUP, "unmanaged.fs", new Instrumentation.Variable<Integer>() {
      @Override
      public Integer getValue() {
        return unmanagedFileSystems.get();
      }
    });
    instrumentation.addSampler(INSTRUMENTATION_GROUP, "unmanaged.fs", 60, new Instrumentation.Variable<Long>() {
      @Override
      public Long getValue() {
        return (long) unmanagedFileSystems.get();
      }
    });
View Full Code Here

      UserGroupInformation ugi = getUGI(user);
      return ugi.doAs(new PrivilegedExceptionAction<T>() {
        public T run() throws Exception {
          Configuration namenodeConf = createNameNodeConf(conf);
          FileSystem fs = createFileSystem(namenodeConf);
          Instrumentation instrumentation = getServer().get(Instrumentation.class);
          Instrumentation.Cron cron = instrumentation.createCron();
          try {
            checkNameNodeHealth(fs);
            cron.start();
            return executor.execute(fs);
          }
          finally {
            cron.stop();
            instrumentation.addCron(INSTRUMENTATION_GROUP, executor.getClass().getSimpleName(), cron);
            closeFileSystem(fs);
          }
        }
      });
    }
View Full Code Here

          Configuration namenodeConf = createNameNodeConf(conf);
          JobClient jobClient = createJobClient(jobtrackerConf);
          try {
            checkJobTrackerHealth(jobClient);
            FileSystem fs = createFileSystem(namenodeConf);
            Instrumentation instrumentation = getServer().get(Instrumentation.class);
            Instrumentation.Cron cron = instrumentation.createCron();
            try {
              checkNameNodeHealth(fs);
              cron.start();
              return executor.execute(jobClient, fs);
            }
            finally {
              cron.stop();
              instrumentation.addCron(INSTRUMENTATION_GROUP, executor.getClass().getSimpleName(), cron);
              closeFileSystem(fs);
            }
          }
          finally {
            closeJobClient(jobClient);
View Full Code Here

      LOG.debug("Scheduling callable [{}], interval [{}] seconds, delay [{}] in [{}]",
                new Object[]{callable, delay, interval, unit});
      Runnable r = new Runnable() {
        public void run() {
          String instrName = callable.getClass().getSimpleName();
          Instrumentation instr = getServer().get(Instrumentation.class);
          if (getServer().getStatus() == Server.Status.HALTED) {
            LOG.debug("Skipping [{}], server status [{}]", callable, getServer().getStatus());
            instr.incr(INST_GROUP, instrName + ".skips", 1);
          }
          else {
            LOG.debug("Executing [{}]", callable);
            instr.incr(INST_GROUP, instrName + ".execs", 1);
            Instrumentation.Cron cron = instr.createCron().start();
            try {
              callable.call();
            }
            catch (Exception ex) {
              instr.incr(INST_GROUP, instrName + ".fails", 1);
              LOG.error("Error executing [{}], {}", new Object[]{callable, ex.getMessage(), ex});
            }
            finally {
              instr.addCron(INST_GROUP, instrName, cron.stop());
            }
          }
        }
      };
      scheduler.scheduleWithFixedDelay(r, delay, interval, unit);
View Full Code Here

    XConfiguration conf = new XConfiguration();
    conf.set("server.services", services);
    Server server = new Server("server", dir, dir, dir, dir, conf);
    server.init();

    Instrumentation instrumentation = server.get(Instrumentation.class);
    Assert.assertNotNull(instrumentation);
    instrumentation.incr("g", "c", 1);
    instrumentation.incr("g", "c", 2);
    instrumentation.incr("g", "c1", 2);

    Instrumentation.Cron cron = instrumentation.createCron();
    cron.start();
    sleep(100);
    cron.stop();
    instrumentation.addCron("g", "t", cron);
    cron = instrumentation.createCron();
    cron.start();
    sleep(200);
    cron.stop();
    instrumentation.addCron("g", "t", cron);

    Instrumentation.Variable<String> var = new Instrumentation.Variable<String>() {
      @Override
      public String getValue() {
        return "foo";
      }
    };
    instrumentation.addVariable("g", "v", var);

    Instrumentation.Variable<Long> varToSample = new Instrumentation.Variable<Long>() {
      @Override
      public Long getValue() {
        return 1L;
      }
    };
    instrumentation.addSampler("g", "s", 10, varToSample);

    Map<String, ?> snapshot = instrumentation.getSnapshot();
    Assert.assertNotNull(snapshot.get("os-env"));
    Assert.assertNotNull(snapshot.get("sys-props"));
    Assert.assertNotNull(snapshot.get("jvm"));
    Assert.assertNotNull(snapshot.get("counters"));
    Assert.assertNotNull(snapshot.get("timers"));
View Full Code Here

                                                         SchedulerService.class.getName()), ",");
    XConfiguration conf = new XConfiguration();
    conf.set("server.services", services);
    Server server = new Server("server", dir, dir, dir, dir, conf);
    server.init();
    Instrumentation instrumentation = server.get(Instrumentation.class);

    final AtomicInteger count = new AtomicInteger();

    Instrumentation.Variable<Long> varToSample = new Instrumentation.Variable<Long>() {
      @Override
      public Long getValue() {
        return (long) count.incrementAndGet();
      }
    };
    instrumentation.addSampler("g", "s", 10, varToSample);

    sleep(2000);
    int i = count.get();
    Assert.assertTrue(i > 0);

    Map<String, Map<String, ?>> snapshot = instrumentation.getSnapshot();
    Map<String, Map<String, Object>> samplers = (Map<String, Map<String, Object>>) snapshot.get("samplers");
    InstrumentationService.Sampler sampler = (InstrumentationService.Sampler) samplers.get("g").get("s");
    Assert.assertTrue(sampler.getRate() > 0);

    server.destroy();
View Full Code Here

        List<GradsVariable>  vars  = gradsDDF.getVariables();
        List<GradsAttribute> attrs = gradsDDF.getAttributes();
        //TODO: ensembles
        List<GradsDimension>       dims = gradsDDF.getDimensions();
        Variable                   v;
        int                        numZ  = 0;
        HashMap<String, Dimension> zDims = new HashMap<String, Dimension>();
        for (GradsDimension dim : dims) {
            String    name  = getVarName(dim);
            int       size  = dim.getSize();
            Dimension ncDim = new Dimension(name, size, true);
            ncFile.addDimension(null, ncDim);
            if (name.equals(ENS_VAR)) {
                v = new Variable(ncFile, null, null, name, DataType.STRING,
                                 name);
                v.addAttribute(new Attribute("standard_name", "ensemble"));
                v.addAttribute(new Attribute(_Coordinate.AxisType,
                                             AxisType.Ensemble.toString()));
                List<String> names =
                    gradsDDF.getEnsembleDimension().getEnsembleNames();
                String[] nameArray = new String[names.size()];
                for (int i = 0; i < nameArray.length; i++) {
                    nameArray[i] = names.get(i);
                }
                Array dataArray = Array.factory(DataType.STRING,
                                      new int[] { nameArray.length },
                                      nameArray);
                v.setCachedData(dataArray, false);
            } else {
                double[] vals = dim.getValues();
                v = new Variable(ncFile, null, null, name, DataType.DOUBLE,
                                 name);
                v.addAttribute(new Attribute("units", dim.getUnit()));
                if (name.equals(Y_VAR)) {
                    v.addAttribute(new Attribute("long_name", "latitude"));
                    v.addAttribute(new Attribute("standard_name",
                            "latitude"));
                    v.addAttribute(new Attribute("axis", "Y"));
                    sizeY = dim.getSize();
                    v.addAttribute(new Attribute(_Coordinate.AxisType,
                            AxisType.Lat.toString()));
                } else if (name.equals(X_VAR)) {
                    v.addAttribute(new Attribute("long_name", "longitude"));
                    v.addAttribute(new Attribute("standard_name",
                            "longitude"));
                    v.addAttribute(new Attribute("axis", "X"));
                    v.addAttribute(new Attribute(_Coordinate.AxisType,
                            AxisType.Lon.toString()));
                    sizeX = dim.getSize();
                } else if (name.equals(Z_VAR)) {
                    numZ = size;
                    zDims.put(name, ncDim);
                    v.addAttribute(new Attribute("long_name", "level"));
                    addZAttributes(dim, v);
                } else if (name.equals(TIME_VAR)) {
                    v.addAttribute(new Attribute("long_name", "time"));
                    v.addAttribute(new Attribute(_Coordinate.AxisType,
                            AxisType.Time.toString()));
                }
                ArrayDouble.D1 varArray = new ArrayDouble.D1(size);
                for (int i = 0; i < vals.length; i++) {
                    varArray.set(i, vals[i]);
                }
                v.setCachedData(varArray, false);
            }
            ncFile.addVariable(null, v);
        }
        if (numZ > 0) {
            GradsDimension zDim = gradsDDF.getZDimension();
            double[]       vals = zDim.getValues();
            for (GradsVariable var : vars) {
                int nl = var.getNumLevels();
                if ((nl > 0) && (nl != numZ)) {
                    String name = Z_VAR + nl;
                    if (zDims.get(name) == null) {
                        Dimension ncDim = new Dimension(name, nl, true);
                        ncFile.addDimension(null, ncDim);
                        Variable vz = new Variable(ncFile, null, null, name,
                                          DataType.DOUBLE, name);
                        vz.addAttribute(new Attribute("long_name", name));
                        vz.addAttribute(new Attribute("units",
                                zDim.getUnit()));
                        addZAttributes(zDim, vz);
                        ArrayDouble.D1 varArray = new ArrayDouble.D1(nl);
                        for (int i = 0; i < nl; i++) {
                            varArray.set(i, vals[i]);
                        }
                        vz.setCachedData(varArray, false);
                        ncFile.addVariable(null, vz);
                        zDims.put(name, ncDim);
                    }
                }
            }
        }
        zDims = null;
        for (GradsVariable var : vars) {
            String coords = "latitude longitude";
            int    nl     = var.getNumLevels();
            if (nl > 0) {
                if (nl == numZ) {
                    coords = "level " + coords;
                } else {
                    coords = Z_VAR + nl + " " + coords;
                }
            }
            coords = "time " + coords;
            if (gradsDDF.getEnsembleDimension() != null) {
                coords = "ensemble " + coords;
            }
            v = new Variable(ncFile, null, null, var.getName(),
                             DataType.FLOAT, coords);
            v.addAttribute(new Attribute("long_name", var.getDescription()));
            if (var.getUnitName() != null) {
                v.addAttribute(new Attribute("units", var.getUnitName()));
            }
View Full Code Here

   * @param ncfile the NetcdfFile to test
   * @return true if we think this is a Zebra file.
   */
  public static boolean isMine(NetcdfFile ncfile) {

    Variable v = ncfile.findVariable("time_offset");
    if (v == null || !v.isCoordinateVariable()) return false;
    String desc = v.getDescription();
    if (desc == null || !desc.equals("Time delta from start_time")) return false;

    if (null == ncfile.findGlobalAttribute( "start_date")) return false;
    if (null == ncfile.findGlobalAttribute( "start_time")) return false;

View Full Code Here

      start = df.parse(start_date);
    } catch (ParseException e) {
      throw new RuntimeException("Cant read start_date="+start_date);
    }

    Variable v = ds.findVariable("time_offset");
    v.addAttribute(new Attribute( "units", "seconds since "+dfo.toDateTimeString(start)));

    Group root = ds.getRootGroup();
    root.addAttribute(new Attribute( "Convention", "Suomi-Station-CDM"));   
    ds.finish();
  }
View Full Code Here

TOP

Related Classes of com.cloudera.lib.service.Instrumentation$Variable

Copyright © 2018 www.massapicom. 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.