001/* 002 * (C) Copyright 2009 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Thierry Delprat 018 */ 019package org.nuxeo.ecm.platform.importer.executor.jaxrs; 020 021import javax.ws.rs.GET; 022import javax.ws.rs.Path; 023import javax.ws.rs.Produces; 024import javax.ws.rs.QueryParam; 025 026import org.apache.commons.logging.Log; 027import org.apache.commons.logging.LogFactory; 028import org.nuxeo.ecm.platform.importer.base.GenericMultiThreadedImporter; 029import org.nuxeo.ecm.platform.importer.base.ImporterRunner; 030import org.nuxeo.ecm.platform.importer.base.ImporterRunnerConfiguration; 031import org.nuxeo.ecm.platform.importer.filter.EventServiceConfiguratorFilter; 032import org.nuxeo.ecm.platform.importer.filter.ImporterFilter; 033import org.nuxeo.ecm.platform.importer.service.DefaultImporterService; 034import org.nuxeo.ecm.platform.importer.source.RandomTextSourceNode; 035import org.nuxeo.ecm.platform.importer.source.SourceNode; 036import org.nuxeo.runtime.api.Framework; 037 038@Path("randomImporter") 039public class RandomImporterExecutor extends AbstractJaxRSImporterExecutor { 040 041 private static final Log log = LogFactory.getLog(RandomImporterExecutor.class); 042 043 @Override 044 protected Log getJavaLogger() { 045 return log; 046 } 047 048 @GET 049 @Path("run") 050 @Produces("text/plain; charset=UTF-8") 051 public String run(@QueryParam("targetPath") String targetPath, 052 @QueryParam("skipRootContainerCreation") Boolean skipRootContainerCreation, 053 @QueryParam("batchSize") Integer batchSize, @QueryParam("nbThreads") Integer nbThreads, 054 @QueryParam("interactive") Boolean interactive, @QueryParam("nbNodes") Integer nbNodes, 055 @QueryParam("fileSizeKB") Integer fileSizeKB, @QueryParam("onlyText") Boolean onlyText, 056 @QueryParam("nonUniform") Boolean nonUniform, @QueryParam("withProperties") Boolean withProperties, 057 @QueryParam("blockSyncPostCommitProcessing") Boolean blockSyncPostCommitProcessing, 058 @QueryParam("blockAsyncProcessing") Boolean blockAsyncProcessing, 059 @QueryParam("blockIndexing") Boolean blockIndexing, @QueryParam("bulkMode") Boolean bulkMode, 060 @QueryParam("transactionTimeout") Integer transactionTimeout, 061 @QueryParam("lang") String lang) { 062 if (onlyText == null) { 063 onlyText = true; 064 } 065 if (nonUniform == null) { 066 nonUniform = false; 067 } 068 if (withProperties == null) { 069 withProperties = false; 070 } 071 if (bulkMode == null) { 072 bulkMode = true; 073 } 074 getLogger().info("Init Random text generator"); 075 SourceNode source = RandomTextSourceNode.init(nbNodes, fileSizeKB, onlyText, nonUniform, withProperties, lang); 076 getLogger().info("Random text generator initialized"); 077 078 ImporterRunnerConfiguration configuration = new ImporterRunnerConfiguration.Builder(source, targetPath, 079 getLogger()).skipRootContainerCreation(skipRootContainerCreation) 080 .batchSize(batchSize) 081 .nbThreads(nbThreads) 082 .build(); 083 GenericMultiThreadedImporter runner = new GenericMultiThreadedImporter(configuration); 084 runner.setEnablePerfLogging(Framework.getService( 085 DefaultImporterService.class).getEnablePerfLogging()); 086 087 ImporterFilter filter = new EventServiceConfiguratorFilter(blockSyncPostCommitProcessing, blockAsyncProcessing, 088 !onlyText, blockIndexing, bulkMode); 089 runner.addFilter(filter); 090 if (transactionTimeout != null) { 091 runner.setTransactionTimeout(transactionTimeout); 092 } 093 String res = run(runner, interactive); 094 return res; 095 } 096 097 @Override 098 public String run(ImporterRunner runner, Boolean interactive) { 099 return doRun(runner, interactive); 100 } 101 102}