List of usage examples for org.apache.commons.logging Log isDebugEnabled
boolean isDebugEnabled();
From source file:org.openspaces.grid.gsm.machines.MachinesSlaUtils.java
public static Collection<GridServiceAgent> sortAndFilterAgents(GridServiceAgent[] agents, ElasticMachineProvisioningConfig machineProvisioningConfig, Log logger) { Set<GridServiceAgent> filteredAgents = new LinkedHashSet<GridServiceAgent>(); //maintain order for (final GridServiceAgent agent : agents) { if (!agent.isDiscovered()) { if (logger.isDebugEnabled()) { logger.debug(/*from ww w . ja v a 2 s . co m*/ "Agent " + MachinesSlaUtils.machineToString(agent.getMachine()) + " has shutdown."); } } else if (!MachinesSlaUtils.isAgentConformsToMachineProvisioningConfig(agent, machineProvisioningConfig)) { if (logger.isDebugEnabled()) { agent.getExactZones().isStasfies(machineProvisioningConfig.getGridServiceAgentZones()); ExactZonesConfig agentZones = agent.getExactZones(); ZonesConfig puZones = machineProvisioningConfig.getGridServiceAgentZones(); boolean isDedicatedManagedmentMachines = machineProvisioningConfig .isDedicatedManagementMachines(); boolean isManagementRunningOnMachine = MachinesSlaUtils .isManagementRunningOnMachine(agent.getMachine()); StringBuilder logMessage = new StringBuilder(); logMessage.append("Agent ").append(MachinesSlaUtils.machineToString(agent.getMachine())) .append(" does not conform to machine provisioning SLA. ").append("Agent zones: ") .append(agentZones).append(",").append("PU zones: ").append(puZones).append(", ") .append("Is dedicated management machines: ").append(isDedicatedManagedmentMachines) .append(", ").append("Is management running on machine: ") .append(isManagementRunningOnMachine); logger.debug(logMessage.toString()); } } else { if (logger.isTraceEnabled()) { logger.trace("Agent " + MachinesSlaUtils.machineToString(agent.getMachine()) + " conforms to machine provisioning SLA."); } filteredAgents.add(agent); } } //TODO: Move this sort into the bin packing solver. It already has the priority of each machine // so it can sort it by itself. final List<GridServiceAgent> sortedFilteredAgents = MachinesSlaUtils.sortManagementFirst(filteredAgents); if (logger.isDebugEnabled()) { logger.debug("Provisioned Agents: " + MachinesSlaUtils.machinesToString(sortedFilteredAgents)); } return sortedFilteredAgents; }
From source file:org.openspaces.grid.gsm.rebalancing.RebalancingUtils.java
static FutureStatefulProcessingUnitInstance relocateProcessingUnitInstanceAsync( final GridServiceContainer targetContainer, final ProcessingUnitInstance puInstance, final Log logger, final long duration, final TimeUnit timeUnit) { final ProcessingUnit pu = puInstance.getProcessingUnit(); final GridServiceContainer[] replicationSourceContainers = getReplicationSourceContainers(puInstance); final int instanceId = puInstance.getInstanceId(); final AtomicReference<Throwable> relocateThrowable = new AtomicReference<Throwable>(); final Admin admin = puInstance.getAdmin(); final int runningNumber = puInstance.getClusterInfo().getRunningNumber(); final String puName = puInstance.getName(); final GridServiceContainer sourceContainer = puInstance.getGridServiceContainer(); final Set<ProcessingUnitInstance> puInstancesFromSamePartition = getOtherInstancesFromSamePartition( puInstance);/* w ww. j a v a 2 s . c o m*/ if (logger.isDebugEnabled()) { logger.debug( "Found instances from the same partition as " + RebalancingUtils.puInstanceToString(puInstance) + " : " + RebalancingUtils.puInstancesToString(puInstancesFromSamePartition)); } if (puInstancesFromSamePartition.size() != pu.getNumberOfBackups()) { // total number of instances per partition = numberOfBackups + 1 throw new IllegalStateException("puInstancesFromSamePartition has " + puInstancesFromSamePartition.size() + " instances instead of " + pu.getNumberOfBackups()); } final long start = System.currentTimeMillis(); final long end = start + timeUnit.toMillis(duration); ((InternalAdmin) admin).scheduleAdminOperation(new Runnable() { public void run() { try { logger.debug("Relocation of " + RebalancingUtils.puInstanceToString(puInstance) + " to " + ContainersSlaUtils.gscToString(targetContainer) + " has started."); puInstance.relocate(targetContainer); } catch (AdminException e) { logger.error("Admin exception " + e.getMessage(), e); relocateThrowable.set(e); } catch (Throwable e) { logger.error("Unexpected exception " + e.getMessage(), e); relocateThrowable.set(e); } } }); return new FutureStatefulProcessingUnitInstance() { Throwable throwable; ProcessingUnitInstance newInstance; public boolean isTimedOut() { return System.currentTimeMillis() > end; } public boolean isDone() { endRelocation(); return isTimedOut() || throwable != null || newInstance != null; } public ProcessingUnitInstance get() throws ExecutionException, IllegalStateException, TimeoutException { endRelocation(); ExecutionException exception = getException(); if (exception != null) { throw exception; } if (newInstance == null) { if (isTimedOut()) { throw new TimeoutException("Relocation timeout"); } throw new IllegalStateException("Async operation is not done yet."); } return newInstance; } public Date getTimestamp() { return new Date(start); } public ExecutionException getException() { endRelocation(); if (throwable != null) { return new ExecutionException(throwable.getMessage(), throwable); } return null; } /** * populates this.exception or this.newInstance if relocation is complete */ private void endRelocation() { boolean inProgress = true; tryStateChange(); // this makes relocation synchronous if (newInstance != null || throwable != null) { inProgress = false; } if (inProgress) { if (logger.isDebugEnabled()) { logger.debug("Relocation from " + ContainersSlaUtils.gscToString(getSourceContainer()) + " to " + ContainersSlaUtils.gscToString(getTargetContainer()) + " is in progress."); } // do nothing. relocate() method running on another thread has not returned yet. } } private void tryStateChange() { ProcessingUnitInstance relocatedInstance = getRelocatedProcessingUnitInstance(); if (relocatedInstance != null) { if (relocatedInstance.getGridServiceContainer().equals(targetContainer)) { if (relocatedInstance.getSpaceInstance() != null && relocatedInstance.getSpaceInstance().getMode() != SpaceMode.NONE) { if (logger.isDebugEnabled()) { logger.debug( "Relocation from " + ContainersSlaUtils.gscToString(getSourceContainer()) + " to " + ContainersSlaUtils.gscToString(getTargetContainer()) + " had ended successfully."); } newInstance = relocatedInstance; } } else { if (logger.isDebugEnabled()) { logger.debug("Relocation from " + ContainersSlaUtils.gscToString(getSourceContainer()) + " to " + ContainersSlaUtils.gscToString(getTargetContainer()) + " has ended with an error."); } throwable = new WrongContainerProcessingUnitRelocationException(puInstance, targetContainer); } } } private ProcessingUnitInstance getRelocatedProcessingUnitInstance() { for (GridServiceContainer container : admin.getGridServiceContainers()) { for (ProcessingUnitInstance instance : container.getProcessingUnitInstances(puName)) { if (!instance.equals(puInstance) && instance.getClusterInfo().getRunningNumber() == runningNumber && !puInstancesFromSamePartition.contains(instance)) { return instance; } } } return null; } private boolean isAtLeastOneInstanceValid(Set<ProcessingUnitInstance> instances) { boolean isValidState = false; for (ProcessingUnitInstance instance : instances) { if (instance.isDiscovered() && instance.getGridServiceContainer().isDiscovered()) { isValidState = true; break; } } return isValidState; } public String getFailureMessage() { if (isTimedOut()) { return "relocation timeout of processing unit instance " + instanceId + " from " + gscToString(sourceContainer) + " to " + gscToString(targetContainer); } if (getException() != null) { return getException().getMessage(); } throw new IllegalStateException("Relocation has not encountered any failure."); } public GridServiceContainer getTargetContainer() { return targetContainer; } public ProcessingUnit getProcessingUnit() { return pu; } public int getInstanceId() { return instanceId; } public GridServiceContainer getSourceContainer() { return sourceContainer; } public GridServiceContainer[] getReplicaitonSourceContainers() { return replicationSourceContainers; } }; }
From source file:org.ops4j.gaderian.service.impl.AssemblyInstructionImpl.java
private void autowireService(Object service, String propertyName, AssemblyParameters factoryParameters) { Class propertyType = PropertyUtils.getPropertyType(service, propertyName); final Module invokingModule = factoryParameters.getInvokingModule(); final Log log = factoryParameters.getLog(); try {/*from ww w . j a v a 2 s .c om*/ // Ignore properties for which there are no corresponding // service points... if (invokingModule.containsService(propertyType)) { Object collaboratingService = invokingModule.getService(propertyType); PropertyUtils.write(service, propertyName, collaboratingService); if (log.isDebugEnabled()) { log.debug("Autowired service property " + propertyName + " to " + collaboratingService); } } } catch (Exception ex) { invokingModule.getErrorHandler().error(log, ServiceMessages.autowirePropertyFailure(propertyName, factoryParameters.getServiceId(), ex), getLocation(), ex); } }
From source file:org.ops4j.gaderian.service.impl.BuilderFacet.java
/** * Wire (or auto-wire) the property; return the name of the property actually set (if a property * is set, which is not always the case). *//*from w ww. ja v a2s. com*/ public String wireProperty(Object service, AssemblyParameters assemblyParameters) { try { // Autowire the property (if possible). String autowirePropertyName = autowire(service, assemblyParameters); if (autowirePropertyName != null) return autowirePropertyName; // There will be a facet for log, messages, service-id, etc. even if no // property name is specified, so we skip it here. In many cases, those // facets will have just done an autowire. if (_propertyName == null) return null; Class targetType = PropertyUtils.getPropertyType(service, _propertyName); Object value = getFacetValue(assemblyParameters, targetType); PropertyUtils.write(service, _propertyName, value); final Log log = assemblyParameters.getLog(); if (log.isDebugEnabled()) log.debug("Set property " + _propertyName + " to " + value); return _propertyName; } catch (Exception ex) { assemblyParameters.getErrorLog().error(ex.getMessage(), getLocation(), ex); return null; } }
From source file:org.ops4j.gaderian.service.impl.BuilderFacet.java
/** * Attempts to autowire a property of the target. This requires that * <ul>// w ww .j av a 2 s . c om * <li>The facet type defines a default property name and facet type * <li>The facet instance does not have a specified property name * <li>The (default) property is writeable * <li>The (default) property is assignable from the facet type * </ul> * If all conditions are met, then the property is updated to the facet value, and the property * name is returned. In all other cases, null is returned. * * @param target * The service implementation being constructed * @param assemblyParameters * the parameters that define the service point and its environment */ private String autowire(Object target, AssemblyParameters assemblyParameters) { if (_propertyName != null) return null; String defaultPropertyName = getDefaultPropertyName(); if (defaultPropertyName == null) return null; if (!PropertyUtils.isWritable(target, defaultPropertyName)) return null; Class propertyType = PropertyUtils.getPropertyType(target, defaultPropertyName); if (isAssignableToType(assemblyParameters, propertyType)) { Object facetValue = getFacetValue(assemblyParameters, propertyType); PropertyUtils.write(target, defaultPropertyName, facetValue); Log log = assemblyParameters.getLog(); if (log.isDebugEnabled()) log.debug("Autowired property " + defaultPropertyName + " to " + facetValue); return defaultPropertyName; } return null; }
From source file:org.ops4j.gaderian.service.impl.TestLoggingInterceptorFactory.java
/** * A test for HIVEMIND-55 ... ensure that the LoggingInterceptor can work on * top of a JDK proxy./*from w w w . j a v a2 s . co m*/ */ public void testLoggingOverProxy() { ClassFactory cf = new ClassFactoryImpl(); Runnable r = (Runnable) createMock(Runnable.class); Log log = createMock(Log.class); LoggingInterceptorFactory f = new LoggingInterceptorFactory(); f.setFactory(cf); ServicePoint sp = createMock(ServicePoint.class); Module module = createMock(Module.class); // Training expect(sp.getServiceInterface()).andReturn(Runnable.class); expect(sp.getExtensionPointId()).andReturn("foo.bar"); replayAllRegisteredMocks(); InterceptorStackImpl is = new InterceptorStackImpl(log, sp, r); f.createInterceptor(is, module, Collections.EMPTY_LIST); Runnable ri = (Runnable) is.peek(); verifyAllRegisteredMocks(); // Training expect(log.isDebugEnabled()).andReturn(true); log.debug("BEGIN run()"); log.debug("END run()"); r.run(); replayAllRegisteredMocks(); ri.run(); verifyAllRegisteredMocks(); }
From source file:org.pentaho.cdf.packager.CdfHeadersProvider.java
protected void logError(String msg, Throwable error) { Log log = getLog(); if (log.isDebugEnabled() && error != null) { log.error(msg, error);//w ww.j a va2 s .co m } else { log.error(msg); } }
From source file:org.pentaho.database.dialect.AbstractDatabaseDialect.java
@Override public Driver getDriver(String url) { try {// w w w . j a v a 2s.c o m return DriverManager.getDriver(url); } catch (SQLException e) { Log logger = LogFactory.getLog(IDatabaseDialect.class); if (logger.isDebugEnabled()) { logger.debug("Unable to get driver for url " + url, e); } } return null; }
From source file:org.pentaho.database.service.ServiceLoaderDatabaseDialectProvider.java
Predicate<IDatabaseDialect> usableFilter(Log logger) { if (logger.isDebugEnabled()) { return dialect -> { logger.debug(String.format("Checking for presence of %s ( %s )", dialect.getDatabaseType().getName(), dialect.getNativeDriver())); boolean result = false; if (dialect instanceof IDriverLocator) { result = ((IDriverLocator) dialect).isUsable(); } else if (ClassUtil.canLoadClass(dialect.getNativeDriver())) { result = true;/*from w w w. ja v a 2 s. c o m*/ } if (!result) { logger.debug(String.format("%s not detected.", dialect.getDatabaseType().getName())); } return result; }; } return dialect -> { if (dialect instanceof IDriverLocator) { return ((IDriverLocator) dialect).isUsable(); } else if (ClassUtil.canLoadClass(dialect.getNativeDriver())) { return true; } return false; }; }
From source file:org.pentaho.database.service.ServiceLoaderDatabaseDialectProviderTest.java
@Test public void testUsableFilterNoLog() { Log log = mock(Log.class); when(log.isDebugEnabled()).thenReturn(false); AbstractDatabaseDialect dialect = mock(AbstractDatabaseDialect.class); IDatabaseDialect iDatabaseDialect = mock(IDatabaseDialect.class); when(iDatabaseDialect.getNativeDriver()).thenReturn(Object.class.getCanonicalName()) .thenReturn("fake.class"); when(dialect.isUsable()).thenReturn(true).thenReturn(false); Predicate<IDatabaseDialect> filter = dialectProvider.usableFilter(log); assertTrue(filter.test(dialect));/*from ww w. j a va2s . c om*/ assertFalse(filter.test(dialect)); assertTrue(filter.test(iDatabaseDialect)); assertFalse(filter.test(iDatabaseDialect)); verify(log, never()).debug(anyString()); }