Search in sources :

Example 96 with StopWatch

use of org.apache.commons.lang3.time.StopWatch in project kylo by Teradata.

the class DefaultFeedManagerFeedService method saveFeed.

@Deprecated
private void saveFeed(final FeedMetadata feed) {
    Feed.ID feedId = metadataAccess.commit(() -> {
        Stopwatch stopwatch = Stopwatch.createStarted();
        List<? extends HadoopSecurityGroup> previousSavedSecurityGroups = null;
        // Store the old security groups before saving because we need to compare afterward
        if (!feed.isNew()) {
            Feed previousStateBeforeSaving = feedProvider.findById(feedProvider.resolveId(feed.getId()));
            Map<String, String> userProperties = previousStateBeforeSaving.getUserProperties();
            previousSavedSecurityGroups = previousStateBeforeSaving.getSecurityGroups();
        }
        // if this is the first time saving this feed create a new one
        Feed domainFeed = feedModelTransform.feedToDomain(feed);
        Feed.ID domainId = domainFeed.getId();
        if (domainFeed.getState() == null) {
            domainFeed.setState(Feed.State.ENABLED);
        }
        stopwatch.stop();
        log.debug("Time to transform the feed to a domain object for saving: {} ms", stopwatch.elapsed(TimeUnit.MILLISECONDS));
        stopwatch.reset();
        // initially save the feed
        if (feed.isNew()) {
            stopwatch.start();
            domainFeed = feedProvider.update(domainFeed);
            stopwatch.stop();
            log.debug("Time to save the New feed: {} ms", stopwatch.elapsed(TimeUnit.MILLISECONDS));
            stopwatch.reset();
        }
        final String feedName = FeedNameUtil.fullName(domainFeed.getCategory().getSystemName(), domainFeed.getName());
        // Build preconditions
        stopwatch.start();
        assignFeedDependencies(feed, domainFeed);
        stopwatch.stop();
        log.debug("Time to assignFeedDependencies: {} ms", stopwatch.elapsed(TimeUnit.MILLISECONDS));
        stopwatch.reset();
        // Assign the datasources
        stopwatch.start();
        assignFeedDatasources(feed, domainFeed);
        stopwatch.stop();
        log.debug("Time to assignFeedDatasources: {} ms", stopwatch.elapsed(TimeUnit.MILLISECONDS));
        stopwatch.reset();
        stopwatch.start();
        boolean isStream = feed.getRegisteredTemplate() != null ? feed.getRegisteredTemplate().isStream() : false;
        Long timeBetweenBatchJobs = feed.getRegisteredTemplate() != null ? feed.getRegisteredTemplate().getTimeBetweenStartingBatchJobs() : 0L;
        // sync the feed information to ops manager
        metadataAccess.commit(() -> opsManagerFeedProvider.save(opsManagerFeedProvider.resolveId(domainId.toString()), feedName, isStream, timeBetweenBatchJobs));
        stopwatch.stop();
        log.debug("Time to sync feed data with Operations Manager: {} ms", stopwatch.elapsed(TimeUnit.MILLISECONDS));
        stopwatch.reset();
        // Update hadoop security group polices if the groups changed
        if (!feed.isNew() && !ListUtils.isEqualList(previousSavedSecurityGroups, domainFeed.getSecurityGroups())) {
            stopwatch.start();
            List<? extends HadoopSecurityGroup> securityGroups = domainFeed.getSecurityGroups();
            List<String> groupsAsCommaList = securityGroups.stream().map(group -> group.getName()).collect(Collectors.toList());
            hadoopAuthorizationService.updateSecurityGroupsForAllPolicies(feed.getSystemCategoryName(), feed.getSystemFeedName(), groupsAsCommaList, domainFeed.getProperties());
            stopwatch.stop();
            log.debug("Time to update hadoop security groups: {} ms", stopwatch.elapsed(TimeUnit.MILLISECONDS));
            stopwatch.reset();
        }
        // Update Hive metastore
        if (hiveTargetSyncColumnDescriptions) {
            stopwatch.start();
            final boolean hasHiveDestination = domainFeed.getDestinations().stream().map(FeedDestination::getDatasource).filter(DerivedDatasource.class::isInstance).map(DerivedDatasource.class::cast).anyMatch(datasource -> "HiveDatasource".equals(datasource.getDatasourceType()));
            if (hasHiveDestination) {
                try {
                    feedHiveTableService.updateColumnDescriptions(feed);
                } catch (final DataAccessException e) {
                    log.warn("Failed to update column descriptions for feed: {}", feed.getCategoryAndFeedDisplayName(), e);
                }
            }
            stopwatch.stop();
            log.debug("Time to update hive metastore: {} ms", stopwatch.elapsed(TimeUnit.MILLISECONDS));
            stopwatch.reset();
        }
        // Update Kylo metastore
        stopwatch.start();
        domainFeed = feedProvider.update(domainFeed);
        stopwatch.stop();
        log.debug("Time to call feedProvider.update: {} ms", stopwatch.elapsed(TimeUnit.MILLISECONDS));
        stopwatch.reset();
        return domainFeed.getId();
    }, (e) -> {
        if (feed.isNew() && StringUtils.isNotBlank(feed.getId())) {
            // Rollback ops Manager insert if it is newly created
            metadataAccess.commit(() -> {
                opsManagerFeedProvider.delete(opsManagerFeedProvider.resolveId(feed.getId()));
            });
        }
    });
    if (feedId != null) {
        // set deployed as  a service account since it needs access to the versionable node
        metadataAccess.commit(() -> {
            // TODO TEMPORARY
            com.thinkbiganalytics.metadata.api.versioning.EntityVersion<Feed.ID, Feed> version = feedProvider.createVersion(feedId, null, false);
            feedProvider.setDeployed(feedId, version.getId());
        // TODO TEMPORARY
        }, MetadataAccess.SERVICE);
    }
}
Also used : Action(com.thinkbiganalytics.security.action.Action) RegisteredTemplateService(com.thinkbiganalytics.feedmgr.service.template.RegisteredTemplateService) Category(com.thinkbiganalytics.metadata.api.category.Category) DataSourceProvider(com.thinkbiganalytics.metadata.api.catalog.DataSourceProvider) ReusableTemplateConnectionInfo(com.thinkbiganalytics.feedmgr.rest.model.ReusableTemplateConnectionInfo) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) FeedProvider(com.thinkbiganalytics.metadata.api.feed.FeedProvider) FeedAccessControl(com.thinkbiganalytics.metadata.api.feed.security.FeedAccessControl) Map(java.util.Map) FeedPropertyChangeEvent(com.thinkbiganalytics.metadata.api.event.feed.FeedPropertyChangeEvent) AccessController(com.thinkbiganalytics.security.AccessController) NifiFeed(com.thinkbiganalytics.feedmgr.rest.model.NifiFeed) CategoryAccessControl(com.thinkbiganalytics.metadata.api.category.security.CategoryAccessControl) FeedServicesAccessControl(com.thinkbiganalytics.feedmgr.security.FeedServicesAccessControl) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) FeedManagerTemplateProvider(com.thinkbiganalytics.metadata.api.template.FeedManagerTemplateProvider) FeedManagerTemplateService(com.thinkbiganalytics.feedmgr.service.template.FeedManagerTemplateService) MetadataEventListener(com.thinkbiganalytics.metadata.api.event.MetadataEventListener) Obligation(com.thinkbiganalytics.metadata.rest.model.sla.Obligation) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) LabelValue(com.thinkbiganalytics.rest.model.LabelValue) ActionGroup(com.thinkbiganalytics.security.rest.model.ActionGroup) PageRequest(org.springframework.data.domain.PageRequest) Set(java.util.Set) Page(org.springframework.data.domain.Page) EntityVersionDifference(com.thinkbiganalytics.feedmgr.rest.model.EntityVersionDifference) MetadataEventService(com.thinkbiganalytics.metadata.api.event.MetadataEventService) Serializable(java.io.Serializable) DraftEntityVersion(com.thinkbiganalytics.feedmgr.rest.model.DraftEntityVersion) CategoryProvider(com.thinkbiganalytics.metadata.api.category.CategoryProvider) SecurityModelTransform(com.thinkbiganalytics.security.rest.controller.SecurityModelTransform) DataSourceNotFoundException(com.thinkbiganalytics.metadata.api.catalog.DataSourceNotFoundException) FeedMetadata(com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) ServiceLevelAgreementBuilder(com.thinkbiganalytics.metadata.sla.spi.ServiceLevelAgreementBuilder) RegisteredTemplateRequest(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplateRequest) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) NiFiObjectCache(com.thinkbiganalytics.nifi.rest.NiFiObjectCache) DerivedDatasourceFactory(com.thinkbiganalytics.feedmgr.service.feed.datasource.DerivedDatasourceFactory) MetadataChange(com.thinkbiganalytics.metadata.api.event.MetadataChange) RegisteredTemplate(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate) ObligationGroup(com.thinkbiganalytics.metadata.sla.api.ObligationGroup) Nullable(javax.annotation.Nullable) Datasource(com.thinkbiganalytics.metadata.api.datasource.Datasource) Properties(java.util.Properties) SecurityService(com.thinkbiganalytics.feedmgr.service.security.SecurityService) FeedProperties(com.thinkbiganalytics.metadata.api.feed.FeedProperties) FeedManagerTemplate(com.thinkbiganalytics.metadata.api.template.FeedManagerTemplate) HadoopSecurityGroup(com.thinkbiganalytics.metadata.api.security.HadoopSecurityGroup) ImmutableAllowableAction(com.thinkbiganalytics.security.role.ImmutableAllowableAction) TemplateConnectionUtil(com.thinkbiganalytics.feedmgr.nifi.TemplateConnectionUtil) HadoopAuthorizationService(com.thinkbiganalytics.datalake.authorization.service.HadoopAuthorizationService) ListUtils(org.apache.commons.collections.ListUtils) LoggerFactory(org.slf4j.LoggerFactory) FeedChange(com.thinkbiganalytics.metadata.api.event.feed.FeedChange) NiFiPropertyDescriptorTransform(com.thinkbiganalytics.nifi.rest.model.NiFiPropertyDescriptorTransform) Precondition(com.thinkbiganalytics.policy.precondition.Precondition) PreDestroy(javax.annotation.PreDestroy) DataSetProvider(com.thinkbiganalytics.metadata.api.catalog.DataSetProvider) NifiPropertyUtil(com.thinkbiganalytics.nifi.rest.support.NifiPropertyUtil) Pageable(org.springframework.data.domain.Pageable) MetadataAccess(com.thinkbiganalytics.metadata.api.MetadataAccess) CatalogModelTransform(com.thinkbiganalytics.kylo.catalog.rest.model.CatalogModelTransform) FeedVersions(com.thinkbiganalytics.feedmgr.rest.model.FeedVersions) DeployResponseEntityVersion(com.thinkbiganalytics.feedmgr.rest.model.DeployResponseEntityVersion) FeedDestination(com.thinkbiganalytics.metadata.api.feed.FeedDestination) OpsManagerFeedProvider(com.thinkbiganalytics.metadata.api.feed.OpsManagerFeedProvider) ImmutableAllowedActions(com.thinkbiganalytics.security.role.ImmutableAllowedActions) UserField(com.thinkbiganalytics.feedmgr.rest.model.UserField) ImmutableMap(com.google.common.collect.ImmutableMap) DataSetNotFoundException(com.thinkbiganalytics.metadata.api.catalog.DataSetNotFoundException) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) NotFoundException(javax.ws.rs.NotFoundException) EntityVersion(com.thinkbiganalytics.feedmgr.rest.model.EntityVersion) FeedSummary(com.thinkbiganalytics.feedmgr.rest.model.FeedSummary) InputOutputPort(com.thinkbiganalytics.nifi.feedmgr.InputOutputPort) List(java.util.List) Principal(java.security.Principal) DataSource(com.thinkbiganalytics.metadata.api.catalog.DataSource) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) NifiProcessGroup(com.thinkbiganalytics.nifi.rest.model.NifiProcessGroup) DerivedDatasource(com.thinkbiganalytics.metadata.api.datasource.DerivedDatasource) PreconditionRule(com.thinkbiganalytics.policy.rest.model.PreconditionRule) DataAccessException(org.springframework.dao.DataAccessException) Stopwatch(com.google.common.base.Stopwatch) Feed(com.thinkbiganalytics.metadata.api.feed.Feed) HashMap(java.util.HashMap) AllowedActions(com.thinkbiganalytics.security.action.AllowedActions) UserProperty(com.thinkbiganalytics.feedmgr.rest.model.UserProperty) HashSet(java.util.HashSet) Inject(javax.inject.Inject) UIFeed(com.thinkbiganalytics.feedmgr.rest.model.UIFeed) PropertyExpressionResolver(com.thinkbiganalytics.feedmgr.nifi.PropertyExpressionResolver) ServiceLevelAgreementService(com.thinkbiganalytics.feedmgr.sla.ServiceLevelAgreementService) FeedChangeEvent(com.thinkbiganalytics.metadata.api.event.feed.FeedChangeEvent) Qualifier(org.springframework.beans.factory.annotation.Qualifier) FeedRollbackException(com.thinkbiganalytics.nifi.feedmgr.FeedRollbackException) FeedSource(com.thinkbiganalytics.metadata.api.feed.FeedSource) Nonnull(javax.annotation.Nonnull) FeedNotFoundException(com.thinkbiganalytics.metadata.api.feed.FeedNotFoundException) Logger(org.slf4j.Logger) FeedNameUtil(com.thinkbiganalytics.support.FeedNameUtil) CreateFeedBuilder(com.thinkbiganalytics.feedmgr.nifi.CreateFeedBuilder) FeedHistoryDataReindexingService(com.thinkbiganalytics.feedmgr.service.feed.reindexing.FeedHistoryDataReindexingService) DateTime(org.joda.time.DateTime) UserFieldDescriptor(com.thinkbiganalytics.metadata.api.extension.UserFieldDescriptor) FieldRuleProperty(com.thinkbiganalytics.policy.rest.model.FieldRuleProperty) TimeUnit(java.util.concurrent.TimeUnit) NifiFlowCache(com.thinkbiganalytics.feedmgr.nifi.cache.NifiFlowCache) AbstractMap(java.util.AbstractMap) UserPropertyTransform(com.thinkbiganalytics.feedmgr.service.UserPropertyTransform) NiFiTemplateCache(com.thinkbiganalytics.feedmgr.service.template.NiFiTemplateCache) DependentFeedPrecondition(com.thinkbiganalytics.policy.precondition.DependentFeedPrecondition) PreconditionPolicyTransformer(com.thinkbiganalytics.policy.precondition.transform.PreconditionPolicyTransformer) Comparator(java.util.Comparator) Collections(java.util.Collections) LegacyNifiRestClient(com.thinkbiganalytics.nifi.rest.client.LegacyNifiRestClient) Stopwatch(com.google.common.base.Stopwatch) DerivedDatasource(com.thinkbiganalytics.metadata.api.datasource.DerivedDatasource) DataAccessException(org.springframework.dao.DataAccessException) NifiFeed(com.thinkbiganalytics.feedmgr.rest.model.NifiFeed) Feed(com.thinkbiganalytics.metadata.api.feed.Feed) UIFeed(com.thinkbiganalytics.feedmgr.rest.model.UIFeed)

Example 97 with StopWatch

use of org.apache.commons.lang3.time.StopWatch in project thymeleaf-tests by thymeleaf.

the class ExpressionBenchmark method main.

public static void main(String[] args) throws Exception {
    final Map<String, String> expressionsMap = ExpressionBenchmarkDefinitions.createExpressionsMap();
    final Configuration configuration = new Configuration();
    final IProcessingContext processingContext = new ProcessingContext(new Context());
    final IStandardExpressionParser parser = new StandardExpressionParser();
    for (final Map.Entry<String, String> expressionEntry : expressionsMap.entrySet()) {
        final String expression = expressionEntry.getKey();
        final String expectedParsingResult = expressionEntry.getValue();
        final IStandardExpression parsedExpression = parser.parseExpression(configuration, processingContext, expression);
        Assert.assertNotNull(parsedExpression);
        final String exp = parsedExpression.getStringRepresentation();
        Assert.assertEquals(expectedParsingResult, exp);
    }
    final StopWatch sw = new StopWatch();
    sw.start();
    for (int x = 0; x < 1000; x++) for (final String expression : expressionsMap.keySet()) parser.parseExpression(configuration, processingContext, expression);
    sw.stop();
    System.out.println("First pass: " + sw.toString());
    sw.reset();
    sw.start();
    for (int x = 0; x < 1000; x++) for (final String expression : expressionsMap.keySet()) parser.parseExpression(configuration, processingContext, expression);
    sw.stop();
    System.out.println("Second pass: " + sw.toString());
}
Also used : IProcessingContext(org.thymeleaf.context.IProcessingContext) ProcessingContext(org.thymeleaf.context.ProcessingContext) Context(org.thymeleaf.context.Context) IProcessingContext(org.thymeleaf.context.IProcessingContext) ProcessingContext(org.thymeleaf.context.ProcessingContext) Configuration(org.thymeleaf.Configuration) IProcessingContext(org.thymeleaf.context.IProcessingContext) StopWatch(org.apache.commons.lang3.time.StopWatch) Map(java.util.Map)

Example 98 with StopWatch

use of org.apache.commons.lang3.time.StopWatch in project hippo by NHS-digital-website.

the class BlockingPooledS3Connector method upload.

/**
 * See {@linkplain PooledS3Connector#upload}.
 */
@Override
public S3ObjectMetadata upload(final Supplier<InputStream> inputStreamSupplier, final String fileName, final String mimeType) {
    final StopWatch stopWatch = logger.reportUploadScheduling(fileName);
    final S3ObjectMetadata uploadedS3FileMetadata;
    try {
        uploadedS3FileMetadata = waitFor(uploadExecutorService, () -> {
            logger.reportUploadStarting(fileName);
            final S3ObjectMetadata uploadedFileMetadata = s3Connector.uploadFile(inputStreamSupplier.get(), fileName, mimeType);
            return uploadedFileMetadata;
        });
        logger.reportUploadStopped(stopWatch, uploadedS3FileMetadata.getReference(), uploadedS3FileMetadata.getSize());
        return uploadedS3FileMetadata;
    } catch (final RuntimeException re) {
        logger.reportUploadFailed(fileName, re);
        throw re;
    }
}
Also used : StopWatch(org.apache.commons.lang3.time.StopWatch)

Example 99 with StopWatch

use of org.apache.commons.lang3.time.StopWatch in project hippo by NHS-digital-website.

the class BlockingPooledS3Connector method download.

/**
 * See {@linkplain PooledS3Connector#download}.
 */
@Override
public void download(final String s3FileReference, final Consumer<S3File> downloadConsumer) {
    final StopWatch stopWatch = logger.reportDownloadScheduling(s3FileReference);
    final S3File downloadedFileMetadata;
    try {
        downloadedFileMetadata = waitFor(downloadExecutorService, () -> {
            logger.reportDownloadStarting(s3FileReference);
            final S3File s3File = s3Connector.downloadFile(s3FileReference);
            downloadConsumer.accept(s3File);
            return s3File;
        });
        logger.reportDownloadStopped(stopWatch, s3FileReference, downloadedFileMetadata.getLength());
    } catch (final RuntimeException re) {
        logger.reportDownloadFailed(s3FileReference, re);
        throw re;
    }
}
Also used : StopWatch(org.apache.commons.lang3.time.StopWatch)

Example 100 with StopWatch

use of org.apache.commons.lang3.time.StopWatch in project TechReborn by TechReborn.

the class Core method init.

@Mod.EventHandler
public void init(FMLInitializationEvent event) throws IllegalAccessException, InstantiationException {
    // World gen
    VeinWorldGenerator.registerTRVeins();
    if (ConfigTechReborn.veinOres) {
        GameRegistry.registerWorldGenerator(VeinWorldGenerator.INSTANCE, 0);
    }
    // Registers Chest Loot
    ModLoot.init();
    // Multiparts
    ModParts.init();
    // Sounds
    ModSounds.init();
    // Compat
    for (ICompatModule compatModule : CompatManager.INSTANCE.compatModules) {
        compatModule.init(event);
    }
    MinecraftForge.EVENT_BUS.register(new StackWIPHandler());
    // Ore Dictionary
    OreDict.init();
    // Recipes
    StopWatch watch = new StopWatch();
    watch.start();
    ModRecipes.init();
    logHelper.all(watch + " : main recipes");
    watch.stop();
    // Client only init, needs to be done before parts system
    proxy.init(event);
    // WorldGen
    worldGen.load();
    if (!ConfigTechReborn.veinOres) {
        GameRegistry.registerWorldGenerator(worldGen, 0);
    }
    // DungeonLoot.init();
    // Register Gui Handler
    NetworkRegistry.INSTANCE.registerGuiHandler(INSTANCE, new GuiHandler());
    // Achievements
    TRAchievements.init();
    // Multiblock events
    MinecraftForge.EVENT_BUS.register(new MultiblockEventHandler());
    // IDSU manager
    IDSUManager.INSTANCE = new IDSUManager();
    // Event busses
    MinecraftForge.EVENT_BUS.register(IDSUManager.INSTANCE);
    MinecraftForge.EVENT_BUS.register(new MultiblockServerTickHandler());
    MinecraftForge.EVENT_BUS.register(new TRTickHandler());
    MinecraftForge.EVENT_BUS.register(new OreUnifier());
    // Scrapbox
    if (config.ScrapboxDispenser) {
        BlockDispenser.DISPENSE_BEHAVIOR_REGISTRY.putObject(ModItems.scrapBox, new BehaviorDispenseScrapbox());
    }
    logHelper.info("Initialization Complete");
}
Also used : MultiblockServerTickHandler(reborncore.common.multiblock.MultiblockServerTickHandler) MultiblockEventHandler(reborncore.common.multiblock.MultiblockEventHandler) BehaviorDispenseScrapbox(techreborn.dispenser.BehaviorDispenseScrapbox) OreUnifier(techreborn.events.OreUnifier) ICompatModule(techreborn.compat.ICompatModule) StackWIPHandler(techreborn.utils.StackWIPHandler) TRTickHandler(techreborn.events.TRTickHandler) GuiHandler(techreborn.client.GuiHandler) IDSUManager(techreborn.tiles.idsu.IDSUManager) StopWatch(org.apache.commons.lang3.time.StopWatch)

Aggregations

StopWatch (org.apache.commons.lang3.time.StopWatch)528 Test (org.junit.Test)150 EventResult (org.alfresco.bm.event.EventResult)97 DBObject (com.mongodb.DBObject)90 Event (org.alfresco.bm.event.Event)87 FolderData (org.alfresco.bm.cm.FolderData)75 File (java.io.File)71 ArrayList (java.util.ArrayList)49 HashSet (java.util.HashSet)31 Gene (ubic.gemma.model.genome.Gene)31 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)26 BaseTest (org.umlg.sqlg.test.BaseTest)26 Element (org.w3c.dom.Element)25 IOException (java.io.IOException)23 LoadSingleComponentUnitTest (org.alfresco.bm.dataload.LoadSingleComponentUnitTest)23 UserModel (org.alfresco.utility.model.UserModel)23 Collectors (java.util.stream.Collectors)19 HashMap (java.util.HashMap)18 List (java.util.List)18 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)18