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.core.api.validation.DocumentValidationService; 029import org.nuxeo.ecm.platform.importer.base.GenericMultiThreadedImporter; 030import org.nuxeo.ecm.platform.importer.base.ImporterRunner; 031import org.nuxeo.ecm.platform.importer.base.ImporterRunnerConfiguration; 032import org.nuxeo.ecm.platform.importer.filter.EventServiceConfiguratorFilter; 033import org.nuxeo.ecm.platform.importer.filter.ImporterFilter; 034import org.nuxeo.ecm.platform.importer.service.DefaultImporterService; 035import org.nuxeo.ecm.platform.importer.source.RandomTextSourceNode; 036import org.nuxeo.ecm.platform.importer.source.SourceNode; 037import org.nuxeo.runtime.api.Framework; 038 039@Path("randomImporter") 040public class RandomImporterExecutor extends AbstractJaxRSImporterExecutor { 041 042 private static final Log log = LogFactory.getLog(RandomImporterExecutor.class); 043 044 @Override 045 protected Log getJavaLogger() { 046 return log; 047 } 048 049 @GET 050 @Path("run") 051 @Produces("text/plain; charset=UTF-8") 052 public String run(@QueryParam("targetPath") String targetPath, 053 @QueryParam("skipRootContainerCreation") Boolean skipRootContainerCreation, 054 @QueryParam("batchSize") Integer batchSize, @QueryParam("nbThreads") Integer nbThreads, 055 @QueryParam("interactive") Boolean interactive, @QueryParam("nbNodes") Integer nbNodes, 056 @QueryParam("fileSizeKB") Integer fileSizeKB, @QueryParam("onlyText") Boolean onlyText, 057 @QueryParam("nonUniform") Boolean nonUniform, @QueryParam("withProperties") Boolean withProperties, 058 @QueryParam("blockSyncPostCommitProcessing") Boolean blockSyncPostCommitProcessing, 059 @QueryParam("blockAsyncProcessing") Boolean blockAsyncProcessing, 060 @QueryParam("blockIndexing") Boolean blockIndexing, @QueryParam("bulkMode") Boolean bulkMode, 061 @QueryParam("transactionTimeout") Integer transactionTimeout) { 062 063 if (onlyText == null) { 064 onlyText = true; 065 } 066 if (nonUniform == null) { 067 nonUniform = false; 068 } 069 if (withProperties == null) { 070 withProperties = false; 071 } 072 if (bulkMode == null) { 073 bulkMode = true; 074 } 075 getLogger().info("Init Random text generator"); 076 SourceNode source = RandomTextSourceNode.init(nbNodes, fileSizeKB, onlyText, nonUniform, withProperties); 077 getLogger().info("Random text generator initialized"); 078 079 ImporterRunnerConfiguration configuration = new ImporterRunnerConfiguration.Builder(source, targetPath, 080 getLogger()).skipRootContainerCreation(skipRootContainerCreation) 081 .batchSize(batchSize) 082 .nbThreads(nbThreads) 083 .build(); 084 GenericMultiThreadedImporter runner = new GenericMultiThreadedImporter(configuration); 085 086 ImporterFilter filter = new EventServiceConfiguratorFilter(blockSyncPostCommitProcessing, blockAsyncProcessing, 087 !onlyText, blockIndexing, bulkMode); 088 runner.addFilter(filter); 089 if (transactionTimeout != null) { 090 Framework.getService(DefaultImporterService.class).setTransactionTimeout(transactionTimeout); 091 } 092 String res = run(runner, interactive); 093 return res; 094 } 095 096 @Override 097 public String run(ImporterRunner runner, Boolean interactive) { 098 return doRun(runner, interactive); 099 } 100 101}