@Override public void postToFeed(final User user, final Throwable ex) { LogHelper.logException(this.getClass(), ex); try { postToFeed(user, ExceptionUtils.getStackTrace(ex), FeedType.error); } catch (NimbitsException e) { LogHelper.logException(this.getClass(), e); } }
static void registerJars(List<String> newJars) throws IllegalArgumentException { LogHelper console = getConsole(); try { ClassLoader loader = Thread.currentThread().getContextClassLoader(); ClassLoader newLoader = Utilities.addToClassPath(loader, newJars.toArray(new String[0])); Thread.currentThread().setContextClassLoader(newLoader); SessionState.get().getConf().setClassLoader(newLoader); console.printInfo("Added " + newJars + " to class path"); } catch (Exception e) { String message = "Unable to register " + newJars; throw new IllegalArgumentException(message, e); } }
static boolean unregisterJar(List<String> jarsToUnregister) { LogHelper console = getConsole(); try { Utilities.removeFromClassPath(jarsToUnregister.toArray(new String[0])); console.printInfo("Deleted " + jarsToUnregister + " from class path"); return true; } catch (Exception e) { console.printError( "Unable to unregister " + jarsToUnregister + "\nException: " + e.getMessage(), "\n" + org.apache.hadoop.util.StringUtils.stringifyException(e)); return false; } }
@Override public void processCalculations(final User u, final Entity point, final Value value) throws NimbitsException { final List<Entity> calculations = EntityServiceFactory.getInstance().getEntityByTrigger(u, point, EntityType.calculation); for (final Entity entity : calculations) { Calculation c = (Calculation) entity; try { final List<Entity> target = EntityServiceFactory.getInstance().getEntityByKey(u, c.getTarget(), EntityType.point); if (target.isEmpty()) { log.severe("Point target was null " + c.getTarget()); log.severe(c.getFormula()); log.severe("trigger: " + c.getTrigger()); disableCalc(u, c); } else { log.info("Solving calc" + c.getFormula()); final Value result = solveEquation(u, c); log.info("result" + result); ValueServiceFactory.getInstance().recordValue(u, target.get(0), result); } } catch (NimbitsException e1) { LogHelper.logException(this.getClass(), e1); disableCalc(u, c); } } }
/** * This does the work of main, but it never calls System.exit, so it is appropriate to be called * progrmmatically. Termination of the program with a message to the user is indicated by throwing * Daikon.TerminationMessage. * * @see #main(String[]) * @see daikon.Daikon.TerminationMessage */ public static void mainHelper(final String[] args) throws FileNotFoundException, IOException, ClassNotFoundException { daikon.LogHelper.setupLogs(daikon.LogHelper.INFO); LongOpt[] longopts = new LongOpt[] { new LongOpt(Daikon.suppress_redundant_SWITCH, LongOpt.NO_ARGUMENT, null, 0), new LongOpt(Daikon.config_option_SWITCH, LongOpt.REQUIRED_ARGUMENT, null, 0), new LongOpt(Daikon.debugAll_SWITCH, LongOpt.NO_ARGUMENT, null, 0), new LongOpt(Daikon.debug_SWITCH, LongOpt.REQUIRED_ARGUMENT, null, 0), }; Getopt g = new Getopt("daikon.ExtractConsequent", args, "h", longopts); int c; while ((c = g.getopt()) != -1) { switch (c) { case 0: // got a long option String option_name = longopts[g.getLongind()].getName(); if (Daikon.help_SWITCH.equals(option_name)) { System.out.println(usage); throw new Daikon.TerminationMessage(); } else if (Daikon.suppress_redundant_SWITCH.equals(option_name)) { Daikon.suppress_redundant_invariants_with_simplify = true; } else if (Daikon.config_option_SWITCH.equals(option_name)) { String item = Daikon.getOptarg(g); daikon.config.Configuration.getInstance().apply(item); break; } else if (Daikon.debugAll_SWITCH.equals(option_name)) { Global.debugAll = true; } else if (Daikon.debug_SWITCH.equals(option_name)) { LogHelper.setLevel(Daikon.getOptarg(g), LogHelper.FINE); } else { throw new RuntimeException("Unknown long option received: " + option_name); } break; case 'h': System.out.println(usage); throw new Daikon.TerminationMessage(); case '?': break; // getopt() already printed an error default: System.out.println("getopt() returned " + c); break; } } // The index of the first non-option argument -- the name of the file int fileIndex = g.getOptind(); if (args.length - fileIndex != 1) { throw new Daikon.TerminationMessage("Wrong number of arguments." + Daikon.lineSep + usage); } String filename = args[fileIndex]; PptMap ppts = FileIO.read_serialized_pptmap( new File(filename), true // use saved config ); extract_consequent(ppts); }
public static IFileArtifactRepository getAggregatedBundleRepository( IProvisioningAgent agent, IProfile profile, int repoFilter) { List<IFileArtifactRepository> bundleRepositories = new ArrayList<IFileArtifactRepository>(); // we check for a shared bundle pool first as it should be preferred over the user bundle pool // in a shared install IArtifactRepositoryManager manager = getArtifactRepositoryManager(agent); if ((repoFilter & AGGREGATE_SHARED_CACHE) != 0) { String sharedCache = profile.getProperty(IProfile.PROP_SHARED_CACHE); if (sharedCache != null) { try { URI repoLocation = new File(sharedCache).toURI(); IArtifactRepository repository = manager.loadRepository(repoLocation, null); if (repository != null && repository instanceof IFileArtifactRepository && !bundleRepositories.contains(repository)) bundleRepositories.add((IFileArtifactRepository) repository); } catch (ProvisionException e) { // skip repository if it could not be read } } } if ((repoFilter & AGGREGATE_CACHE) != 0) { IFileArtifactRepository bundlePool = Util.getBundlePoolRepository(agent, profile); if (bundlePool != null) bundleRepositories.add(bundlePool); } if ((repoFilter & AGGREGATE_CACHE_EXTENSIONS) != 0) { List<String> repos = getListProfileProperty(profile, CACHE_EXTENSIONS); for (String repo : repos) { try { URI repoLocation; try { repoLocation = new URI(repo); } catch (URISyntaxException e) { // in 1.0 we wrote unencoded URL strings, so try as an unencoded string repoLocation = URIUtil.fromString(repo); } IArtifactRepository repository = manager.loadRepository(repoLocation, null); if (repository != null && repository instanceof IFileArtifactRepository && !bundleRepositories.contains(repository)) bundleRepositories.add((IFileArtifactRepository) repository); } catch (ProvisionException e) { // skip repositories that could not be read } catch (URISyntaxException e) { // unexpected, URLs should be pre-checked LogHelper.log(new Status(IStatus.ERROR, Activator.ID, e.getMessage(), e)); } } } return new AggregatedBundleRepository(agent, bundleRepositories); }
@Override @SuppressWarnings(Const.WARNING_UNCHECKED) public void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException { // PrintWriter out; // out = resp.getWriter(); try { processGet(); } catch (NimbitsException e) { LogHelper.logException(IdlePointCron.class, e); } }
protected static int processGet() throws NimbitsException { final List<Entity> points = EntityServiceFactory.getInstance().getIdleEntities(); log.info("Processing " + points.size() + " potentially idle points"); for (final Entity p : points) { try { checkIdle((Point) p); } catch (NimbitsException e) { LogHelper.logException(IdlePointCron.class, e); } } return points.size(); }
/** Returns the platform instance location. */ public Location getInstanceLocation() { if (instanceLocationTracker == null) { Filter filter; try { filter = bundleContext.createFilter(Location.INSTANCE_FILTER); } catch (InvalidSyntaxException e) { LogHelper.log(e); return null; } instanceLocationTracker = new ServiceTracker<Location, Location>(bundleContext, filter, null); instanceLocationTracker.open(); } return instanceLocationTracker.getService(); }
public static synchronized IFileArtifactRepository getBundlePoolRepository( IProvisioningAgent agent, IProfile profile) { URI location = getBundlePoolLocation(agent, profile); if (location == null) return null; IArtifactRepositoryManager manager = getArtifactRepositoryManager(agent); try { return (IFileArtifactRepository) manager.loadRepository(location, null); } catch (ProvisionException e) { // the repository doesn't exist, so fall through and create a new one } try { String repositoryName = Messages.BundlePool; Map<String, String> properties = new HashMap<String, String>(1); properties.put(IRepository.PROP_SYSTEM, Boolean.TRUE.toString()); return (IFileArtifactRepository) manager.createRepository(location, repositoryName, REPOSITORY_TYPE, properties); } catch (ProvisionException e) { LogHelper.log(e); throw new IllegalArgumentException(NLS.bind(Messages.bundle_pool_not_writeable, location)); } }
public static BundleInfo createBundleInfo(File bundleFile, IInstallableUnit unit) { BundleInfo bundleInfo = new BundleInfo(); if (bundleFile != null) bundleInfo.setLocation(bundleFile.toURI()); Collection<IProvidedCapability> capabilities = unit.getProvidedCapabilities(); for (IProvidedCapability capability : capabilities) { String nameSpace = capability.getNamespace(); if (nameSpace.equals("osgi.bundle")) { // $NON-NLS-1$ bundleInfo.setSymbolicName(capability.getName()); bundleInfo.setVersion(capability.getVersion().toString()); } else if (nameSpace.equals("osgi.fragment")) { // $NON-NLS-1$ String fragmentName = capability.getName(); String fragmentHost = getFragmentHost(unit, fragmentName); // shouldn't happen as long as the metadata is well-formed if (fragmentHost == null) LogHelper.log(createError("Unable to find fragment host for IU: " + unit)); // $NON-NLS-1$ else bundleInfo.setFragmentHost(fragmentHost); bundleInfo.setVersion(capability.getVersion().toString()); } } return bundleInfo; }
/** * This does the work of main, but it never calls System.exit, so it is appropriate to be called * progrmmatically. Termination of the program with a message to the user is indicated by throwing * Daikon.TerminationMessage. * * @see #main(String[]) * @see daikon.Daikon.TerminationMessage */ public static void mainHelper(final String[] args) throws FileNotFoundException, StreamCorruptedException, OptionalDataException, IOException, ClassNotFoundException { daikon.LogHelper.setupLogs(daikon.LogHelper.INFO); LongOpt[] longopts = new LongOpt[] { new LongOpt(Daikon.config_option_SWITCH, LongOpt.REQUIRED_ARGUMENT, null, 0), new LongOpt(output_SWITCH, LongOpt.REQUIRED_ARGUMENT, null, 0), new LongOpt(dir_SWITCH, LongOpt.REQUIRED_ARGUMENT, null, 0), new LongOpt(conf_SWITCH, LongOpt.NO_ARGUMENT, null, 0), new LongOpt(filter_SWITCH, LongOpt.NO_ARGUMENT, null, 0), new LongOpt(Daikon.debugAll_SWITCH, LongOpt.NO_ARGUMENT, null, 0), new LongOpt(Daikon.debug_SWITCH, LongOpt.REQUIRED_ARGUMENT, null, 0), new LongOpt(Daikon.ppt_regexp_SWITCH, LongOpt.REQUIRED_ARGUMENT, null, 0), new LongOpt(Daikon.track_SWITCH, LongOpt.REQUIRED_ARGUMENT, null, 0), }; Getopt g = new Getopt("daikon.tools.InvariantChecker", args, "h", longopts); int c; while ((c = g.getopt()) != -1) { switch (c) { case 0: // got a long option String option_name = longopts[g.getLongind()].getName(); if (Daikon.help_SWITCH.equals(option_name)) { System.out.println(usage); throw new Daikon.TerminationMessage(); } else if (conf_SWITCH.equals(option_name)) { doConf = true; } else if (filter_SWITCH.equals(option_name)) { doFilter = true; } else if (dir_SWITCH.equals(option_name)) { dir_file = new File(g.getOptarg()); if (!dir_file.exists() || !dir_file.isDirectory()) throw new Daikon.TerminationMessage("Error reading the directory " + dir_file); } else if (output_SWITCH.equals(option_name)) { output_file = new File(g.getOptarg()); output_stream = new PrintStream(new FileOutputStream(output_file)); } else if (Daikon.config_option_SWITCH.equals(option_name)) { String item = g.getOptarg(); daikon.config.Configuration.getInstance().apply(item); break; } else if (Daikon.debugAll_SWITCH.equals(option_name)) { Global.debugAll = true; } else if (Daikon.debug_SWITCH.equals(option_name)) { LogHelper.setLevel(g.getOptarg(), LogHelper.FINE); } else if (Daikon.track_SWITCH.equals(option_name)) { LogHelper.setLevel("daikon.Debug", LogHelper.FINE); String error = Debug.add_track(g.getOptarg()); if (error != null) { throw new Daikon.TerminationMessage( "Error parsing track argument '" + g.getOptarg() + "' - " + error); } } else { throw new RuntimeException("Unknown long option received: " + option_name); } break; case 'h': System.out.println(usage); throw new Daikon.TerminationMessage(); case '?': break; // getopt() already printed an error default: System.out.println("getopt() returned " + c); break; } } // Loop through each filename specified for (int i = g.getOptind(); i < args.length; i++) { // Get the file and make sure it exists File file = new File(args[i]); if (!file.exists()) { throw new Error("File " + file + " not found."); } // These aren't "endsWith()" because there might be a suffix on the end // (eg, a date). String filename = file.toString(); if (filename.indexOf(".inv") != -1) { if (inv_file != null) { throw new Daikon.TerminationMessage("multiple inv files specified", usage); } inv_file = file; } else if (filename.indexOf(".dtrace") != -1) { dtrace_files.add(filename); } else { throw new Error("Unrecognized argument: " + file); } } if (dir_file == null) { checkInvariants(); return; } // Yoav additions: File[] filesInDir = dir_file.listFiles(); if (filesInDir == null || filesInDir.length == 0) throw new Daikon.TerminationMessage("The directory " + dir_file + " is empty", usage); ArrayList<File> invariants = new ArrayList<File>(); for (File f : filesInDir) if (f.toString().indexOf(".inv") != -1) invariants.add(f); if (invariants.size() == 0) throw new Daikon.TerminationMessage( "Did not find any invariant files in the directory " + dir_file, usage); ArrayList<File> dtraces = new ArrayList<File>(); for (File f : filesInDir) if (f.toString().indexOf(".dtrace") != -1) dtraces.add(f); if (dtraces.size() == 0) throw new Daikon.TerminationMessage( "Did not find any dtrace files in the directory " + dir_file, usage); System.out.println( "Collecting data for invariants files " + invariants + " and dtrace files " + dtraces); dtrace_files.clear(); for (File dtrace : dtraces) { dtrace_files.add(dtrace.toString()); } String commaLine = ""; for (File inFile : invariants) { String name = inFile.getName().replace(".inv", "").replace(".gz", ""); commaLine += "," + name; } outputComma.add(commaLine); commaLine = ""; for (File inFile : invariants) { inv_file = inFile; failedInvariants.clear(); testedInvariants.clear(); error_cnt = 0; output_stream = new PrintStream( new FileOutputStream( inFile.toString().replace(".inv", "").replace(".gz", "") + ".false-positives.txt")); checkInvariants(); output_stream.close(); int failedCount = failedInvariants.size(); int testedCount = testedInvariants.size(); String percent = toPercentage(failedCount, testedCount); commaLine += "," + percent; } outputComma.add(commaLine); System.out.println(); for (String output : outputComma) System.out.println(output); }
public void start(BundleContext context) throws Exception { singleton = this; bundleContext = context; packageAdminTracker = new ServiceTracker<PackageAdmin, PackageAdmin>(context, PackageAdmin.class.getName(), null); packageAdminTracker.open(); authServiceTracker = new AuthServiceTracker(context); authServiceTracker.open(); IEclipsePreferences preferences = DefaultScope.INSTANCE.getNode(ServerConstants.PREFERENCE_SCOPE); Boolean httpsEnabled = new Boolean(preferences.get(ConfigurationFormat.HTTPS_ENABLED, "false")); // $NON-NLS-1$ Dictionary<String, Object> properties = new Hashtable<String, Object>(); properties.put( JettyConstants.CONTEXT_SESSIONINACTIVEINTERVAL, new Integer(4 * 60 * 60)); // 4 hours // properties.put(JettyConstants.CONTEXT_PATH, "/cc"); if (httpsEnabled) { LogHelper.log( new Status(IStatus.INFO, PI_CONFIGURATOR, "Https is enabled", null)); // $NON-NLS-1$ properties.put(JettyConstants.HTTPS_ENABLED, true); properties.put( JettyConstants.HTTPS_PORT, new Integer( preferences.get( HTTPS_PORT, System.getProperty( "org.eclipse.equinox.http.jetty.https.port", "8443")))); //$NON-NLS-1$//$NON-NLS-2$ properties.put( JettyConstants.SSL_KEYSTORE, preferences.get(SSL_KEYSTORE, "keystore")); // $NON-NLS-1$ LogHelper.log( new Status( IStatus.INFO, PI_CONFIGURATOR, "Keystore absolute path is " + preferences.get(SSL_KEYSTORE, "keystore"))); // $NON-NLS-1$ //$NON-NLS-2$ properties.put( JettyConstants.SSL_PASSWORD, preferences.get(SSL_PASSWORD, "password")); // $NON-NLS-1$ properties.put( JettyConstants.SSL_KEYPASSWORD, preferences.get(SSL_KEYPASSWORD, "password")); // $NON-NLS-1$ properties.put( JettyConstants.SSL_PROTOCOL, preferences.get(SSL_PROTOCOL, "SSLv3")); // $NON-NLS-1$ String httpsHost = System.getProperty("org.eclipse.equinox.http.jetty.https.host"); // $NON-NLS-1$ if (httpsHost != null) { properties.put(JettyConstants.HTTPS_HOST, httpsHost); } } String port = null; if (!httpsEnabled) { properties.put(JettyConstants.HTTP_ENABLED, true); port = preferences.get( HTTP_PORT, System.getProperty( "org.eclipse.equinox.http.jetty.http.port", "8080")); // $NON-NLS-1$ //$NON-NLS-2$ properties.put(JettyConstants.HTTP_PORT, new Integer(port)); String httpHost = System.getProperty("org.eclipse.equinox.http.jetty.http.host"); // $NON-NLS-1$ if (httpHost != null) { properties.put(JettyConstants.HTTP_HOST, httpHost); } } // properties to help us filter orion content properties.put("other.info", "org.eclipse.orion"); // $NON-NLS-1$ //$NON-NLS-2$ try { JettyConfigurator.startServer("MasterJetty", properties); // $NON-NLS-1$ } catch (Exception e) { throw new Exception("Error starting Jetty on port: " + port, e); } }
/** Internal log method */ public final void log(String msg) { loghelper.log(msg); }
/** Internal log method */ public void log(String msg, Throwable t) { loghelper.log(msg, t); }
/** Internal log method */ public void log(String msg, Throwable t, int level) { loghelper.log(msg, t, level); }
/** User-level log method ( called from a servlet) */ public void logServlet(String msg, Throwable t) { msg = ("path=\"" + path + "\" :" + msg); loghelperServlet.log(msg, t); }