<commit_before>/**
 * Copyright 2014 Linagora, Université <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.roboconf.debug.sample;

import java.io.File;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;

import net.roboconf.core.actions.ApplicationAction;
import net.roboconf.core.model.helpers.ComponentHelpers;
import net.roboconf.core.model.helpers.InstanceHelpers;
import net.roboconf.core.model.runtime.Component;
import net.roboconf.core.model.runtime.Graphs;
import net.roboconf.core.model.runtime.Instance;
import net.roboconf.dm.environment.iaas.IaasResolver;
import net.roboconf.dm.management.ManagedApplication;
import net.roboconf.dm.management.Manager;
import net.roboconf.dm.rest.client.test.RestTestUtils;
import net.roboconf.iaas.api.IaasException;
import net.roboconf.iaas.api.IaasInterface;

import org.junit.Test;

import com.sun.jersey.test.framework.AppDescriptor;
import com.sun.jersey.test.framework.JerseyTest;
import com.sun.jersey.test.framework.spi.container.TestContainerFactory;
import com.sun.jersey.test.framework.spi.container.grizzly2.web.GrizzlyWebTestContainerFactory;

/**
 * @author <NAME> - Linagora
 */
public class DebugSample extends JerseyTest {

	@Override
	protected AppDescriptor configure() {
		return RestTestUtils.buildTestDescriptor();
	}


	@Override
    public TestContainerFactory getTestContainerFactory() {
        return new GrizzlyWebTestContainerFactory();
    }


	@Test
	public void testApplications() throws Exception {

		loadApplication();
		for( ;; ) {
			// nothing
		}
	}

	public void loadApplication() {

		// Change the logger settings
		Level defaultLevel = Level.FINEST;

		Logger logger = Logger.getLogger( "" );
		logger.setLevel( defaultLevel );
		for( Handler logHandler : logger.getHandlers())
			logHandler.setLevel( defaultLevel );


		// Change the directory location for your own project
		try {
			Manager.INSTANCE.tryToChangeMessageServerIp( "localhost" );
			ManagedApplication ma = Manager.INSTANCE.loadNewApplication( new File( "D:/lamp-legacy-1" ));

			// Use in-memory agents
			Manager.INSTANCE.setIaasResolver( new IaasResolver() {
				@Override
				public IaasInterface findIaasInterface( ManagedApplication ma, Instance instance ) throws IaasException {
					return super.findIaasHandler( IaasResolver.IAAS_IN_MEMORY );
				}
			});

			// All the sub-instances will use the logger plug-in
			for( Instance instance : InstanceHelpers.getAllInstances( ma.getApplication())) {
				if( instance.getParent() != null )
					instance.getComponent().setInstallerName( "logger" );
			}

			// Deploy everything automatically
			for( Instance instance : InstanceHelpers.getAllInstances( ma.getApplication())) {
				Manager.INSTANCE.perform(
						ma.getApplication().getName(),
						ApplicationAction.deploy.toString(),
						InstanceHelpers.computeInstancePath( instance ),
						false );
			}

			// Add fake children instances
			Component warComponent = new Component( "war" ).installerName( "bash" ).alias( "war" );
			Graphs graphs = ma.getApplication().getGraphs();
			Component tomcatComponent = ComponentHelpers.findComponent( graphs, "Tomcat" );
			ComponentHelpers.insertChild( tomcatComponent, warComponent );

			Instance tomcatInstance = InstanceHelpers.findInstanceByPath( ma.getApplication(), "/Tomcat VM 1/Tomcat" );
			Instance war1 = new Instance( "Hello World!" ).component( warComponent );
			InstanceHelpers.insertChild( tomcatInstance, war1 );

			for( int i=0; i<45; i++ ) {
				Instance war2 = new Instance( "ECOM-" + i ).component( warComponent );
				InstanceHelpers.insertChild( tomcatInstance, war2 );
			}

		} catch( Exception e ) {
			e.printStackTrace();
		}
	}
}
<commit_msg>Enhance the log configuration<commit_after>/**
 * Copyright 2014 Linagora, Université <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.roboconf.debug.sample;

import java.io.File;
import java.util.logging.Filter;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;

import net.roboconf.core.actions.ApplicationAction;
import net.roboconf.core.logging.RoboconfLogFormatter;
import net.roboconf.core.model.helpers.ComponentHelpers;
import net.roboconf.core.model.helpers.InstanceHelpers;
import net.roboconf.core.model.runtime.Component;
import net.roboconf.core.model.runtime.Graphs;
import net.roboconf.core.model.runtime.Instance;
import net.roboconf.dm.environment.iaas.IaasResolver;
import net.roboconf.dm.management.ManagedApplication;
import net.roboconf.dm.management.Manager;
import net.roboconf.dm.rest.client.test.RestTestUtils;
import net.roboconf.iaas.api.IaasException;
import net.roboconf.iaas.api.IaasInterface;

import org.junit.Test;

import com.sun.jersey.test.framework.AppDescriptor;
import com.sun.jersey.test.framework.JerseyTest;
import com.sun.jersey.test.framework.spi.container.TestContainerFactory;
import com.sun.jersey.test.framework.spi.container.grizzly2.web.GrizzlyWebTestContainerFactory;

/**
 * @author <NAME> - Linagora
 */
public class DebugSample extends JerseyTest {

	@Override
	protected AppDescriptor configure() {
		return RestTestUtils.buildTestDescriptor();
	}


	@Override
    public TestContainerFactory getTestContainerFactory() {
        return new GrizzlyWebTestContainerFactory();
    }


	@Test
	public void testApplications() throws Exception {

		loadApplication();
		for( ;; ) {
			// nothing
		}
	}

	public void loadApplication() {

		// Change the logger settings
		Level defaultLevel = Level.FINEST;
		Filter logFilter = new Filter() {
			@Override
			public boolean isLoggable( LogRecord record ) {
				return record.getLoggerName().startsWith( "net.roboconf" );
			}
		};

		Logger logger = Logger.getLogger( "" );
		logger.setLevel( defaultLevel );
		logger.setFilter( logFilter );

		for( Handler logHandler : logger.getHandlers()) {
			logHandler.setLevel( defaultLevel );
			logHandler.setFilter( logFilter );
			logHandler.setFormatter( new RoboconfLogFormatter() {
				@Override
				public String format( LogRecord record ) {
					return super.format( record ) + "\n";
				}
			});
		}


		// Change the directory location for your own project
		try {
			Manager.INSTANCE.tryToChangeMessageServerIp( "localhost" );
			ManagedApplication ma = Manager.INSTANCE.loadNewApplication( new File( "D:/lamp-legacy-1" ));

			// Use in-memory agents
			Manager.INSTANCE.setIaasResolver( new IaasResolver() {
				@Override
				public IaasInterface findIaasInterface( ManagedApplication ma, Instance instance ) throws IaasException {
					return super.findIaasHandler( IaasResolver.IAAS_IN_MEMORY );
				}
			});

			// All the sub-instances will use the logger plug-in
			for( Instance instance : InstanceHelpers.getAllInstances( ma.getApplication())) {
				if( instance.getParent() != null )
					instance.getComponent().setInstallerName( "logger" );
			}

			// Deploy everything automatically
			for( Instance instance : InstanceHelpers.getAllInstances( ma.getApplication())) {
				Manager.INSTANCE.perform(
						ma.getApplication().getName(),
						ApplicationAction.deploy.toString(),
						InstanceHelpers.computeInstancePath( instance ),
						false );
			}

			// Add fake children instances
			Component warComponent = new Component( "war" ).installerName( "bash" ).alias( "war" );
			Graphs graphs = ma.getApplication().getGraphs();
			Component tomcatComponent = ComponentHelpers.findComponent( graphs, "Tomcat" );
			ComponentHelpers.insertChild( tomcatComponent, warComponent );

			Instance tomcatInstance = InstanceHelpers.findInstanceByPath( ma.getApplication(), "/Tomcat VM 1/Tomcat" );
			Instance war1 = new Instance( "Hello World!" ).component( warComponent );
			InstanceHelpers.insertChild( tomcatInstance, war1 );

			for( int i=0; i<45; i++ ) {
				Instance war2 = new Instance( "ECOM-" + i ).component( warComponent );
				InstanceHelpers.insertChild( tomcatInstance, war2 );
			}

		} catch( Exception e ) {
			e.printStackTrace();
		}
	}
}

{'fraction_non_alphanumeric': 0.10744073748902547, 'fraction_numerical': 0.003950834064969272, 'mean_word_length': 4.249423963133641, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4150486', 'n_tokens_mistral': 2933, 'n_tokens_neox': 2654, 'n_words': 657}