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            @QueryParam("lang") String lang) {
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, lang);
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        runner.setEnablePerfLogging(Framework.getService(
086                DefaultImporterService.class).getEnablePerfLogging());
087
088        ImporterFilter filter = new EventServiceConfiguratorFilter(blockSyncPostCommitProcessing, blockAsyncProcessing,
089                !onlyText, blockIndexing, bulkMode);
090        runner.addFilter(filter);
091        if (transactionTimeout != null) {
092            runner.setTransactionTimeout(transactionTimeout);
093        }
094        String res = run(runner, interactive);
095        return res;
096    }
097
098    @Override
099    public String run(ImporterRunner runner, Boolean interactive) {
100        return doRun(runner, interactive);
101    }
102
103}