Search in sources :

Example 1 with TraceContext

use of com.google.cloud.trace.core.TraceContext in project activityinfo by bedatadriven.

the class GetSitesHandler method buildQueries.

private void buildQueries() {
    TraceContext queryBuildTrace = Trace.startSpan("ai/cmd/GetSites/buildQuery");
    queryBuildTime.start();
    for (Map.Entry<ResourceId, FormTree> formTreeEntry : formTreeMap.entrySet()) {
        addToQueryMap(formTreeEntry, null);
    }
    if (command.isFetchLinks() && linkedFormTreeMap != null) {
        for (Map.Entry<ResourceId, FormTree> linkedFormTreeEntry : linkedFormTreeMap.entrySet()) {
            for (ActivityLink activityLink : activityLinkMap.get(CuidAdapter.getLegacyIdFromCuid(linkedFormTreeEntry.getKey()))) {
                addToQueryMap(linkedFormTreeEntry, activityLink);
            }
        }
    }
    queryBuildTime.stop();
    Trace.endSpan(queryBuildTrace);
}
Also used : FormTree(org.activityinfo.model.formTree.FormTree) ResourceId(org.activityinfo.model.resource.ResourceId) TraceContext(com.google.cloud.trace.core.TraceContext)

Example 2 with TraceContext

use of com.google.cloud.trace.core.TraceContext in project activityinfo by bedatadriven.

the class GetSitesHandler method fetchActivityMetadata.

private void fetchActivityMetadata(Filter filter) {
    TraceContext activityMetadataTrace = Trace.startSpan("ai/cmd/GetSites/fetchActivityMetadata");
    try {
        metadataTime.start();
        activities = loadMetadata(filter);
    } catch (SQLException excp) {
        throw new CommandException("Could not fetch metadata from server");
    } finally {
        metadataTime.stop();
        Trace.endSpan(activityMetadataTrace);
    }
}
Also used : SQLException(java.sql.SQLException) TraceContext(com.google.cloud.trace.core.TraceContext) CommandException(org.activityinfo.legacy.shared.exception.CommandException)

Example 3 with TraceContext

use of com.google.cloud.trace.core.TraceContext in project activityinfo by bedatadriven.

the class GetSitesHandler method fetchLinkedActivityMetadata.

private void fetchLinkedActivityMetadata(List<Integer> linkedActivitiesToFetch) {
    TraceContext linkedActivityMetadataTrace = Trace.startSpan("ai/cmd/GetSites/fetchLinkedActivityMetadata");
    try {
        metadataTime.start();
        LOGGER.info("Fetching Linked Activity Metadata for: " + Arrays.toString(linkedActivitiesToFetch.toArray()));
        Filter linkedFilter = new Filter();
        linkedFilter.addRestriction(DimensionType.Activity, linkedActivitiesToFetch);
        linkedActivities = loadMetadata(linkedFilter);
    } catch (SQLException excp) {
        throw new CommandException("Could not fetch linked activity metadata from server");
    } finally {
        metadataTime.stop();
        Trace.endSpan(linkedActivityMetadataTrace);
    }
}
Also used : Filter(org.activityinfo.legacy.shared.command.Filter) QueryFilter(org.activityinfo.server.command.QueryFilter) SQLException(java.sql.SQLException) TraceContext(com.google.cloud.trace.core.TraceContext) CommandException(org.activityinfo.legacy.shared.exception.CommandException)

Example 4 with TraceContext

use of com.google.cloud.trace.core.TraceContext in project activityinfo by bedatadriven.

the class GetSitesHandler method mergeMonthlyRootSites.

private void mergeMonthlyRootSites() {
    TraceContext monthlyMergeTrace = Trace.startSpan("ai/cmd/GetSites/executeBatch/mergeMonthlySites");
    monthlyMergeTime.start();
    for (SiteDTO monthlySite : monthlySiteList) {
        if (monthlyRootSiteMap.containsKey(monthlySite.getInstanceId())) {
            SiteDTO rootSite = monthlyRootSiteMap.get(monthlySite.getInstanceId());
            monthlySite.setLocation(rootSite.getLocation());
            monthlySite.setProject(rootSite.getProject());
            monthlySite.setPartner(rootSite.getPartner());
        }
    }
    monthlyMergeTime.stop();
    Trace.endSpan(monthlyMergeTrace);
}
Also used : TraceContext(com.google.cloud.trace.core.TraceContext)

Example 5 with TraceContext

use of com.google.cloud.trace.core.TraceContext in project activityinfo by bedatadriven.

the class GetSitesHandler method queryFormTrees.

private void queryFormTrees() {
    TraceContext formTreeQueryTrace = Trace.startSpan("ai/cmd/GetSites/queryFormTrees");
    treeTime.start();
    Set<ResourceId> formIds = new HashSet<>();
    Set<ResourceId> linkedFormIds = new HashSet<>();
    List<Integer> linkedActivitiesToFetch = new ArrayList<>();
    ResourceId activityFormId;
    for (Activity activity : activities.values()) {
        if (reject(activity)) {
            continue;
        }
        activityFormId = activity.getSiteFormClassId();
        formIds.add(activityFormId);
        if (activity.isMonthly() && command.isFetchAllReportingPeriods()) {
            formIds.add(CuidAdapter.reportingPeriodFormClass(CuidAdapter.getLegacyIdFromCuid(activityFormId)));
        }
        if (command.isFetchLinks()) {
            for (LinkedActivity linkedActivity : activity.getLinkedActivities()) {
                linkedActivitiesToFetch.add(linkedActivity.getActivityId());
                linkedFormIds.add(CuidAdapter.activityFormClass(linkedActivity.getActivityId()));
            }
        }
    }
    formTreeMap = batchFormTreeBuilder.queryTrees(formIds);
    if (!linkedActivitiesToFetch.isEmpty()) {
        fetchLinkedActivityMetadata(linkedActivitiesToFetch);
        linkedFormTreeMap = batchFormTreeBuilder.queryTrees(linkedFormIds);
    }
    treeTime.stop();
    Trace.endSpan(formTreeQueryTrace);
}
Also used : LinkedActivity(org.activityinfo.store.mysql.metadata.LinkedActivity) ResourceId(org.activityinfo.model.resource.ResourceId) TraceContext(com.google.cloud.trace.core.TraceContext) Activity(org.activityinfo.store.mysql.metadata.Activity) LinkedActivity(org.activityinfo.store.mysql.metadata.LinkedActivity)

Aggregations

TraceContext (com.google.cloud.trace.core.TraceContext)8 CommandException (org.activityinfo.legacy.shared.exception.CommandException)4 SQLException (java.sql.SQLException)3 ResourceId (org.activityinfo.model.resource.ResourceId)2 Filter (org.activityinfo.legacy.shared.command.Filter)1 FormTree (org.activityinfo.model.formTree.FormTree)1 QueryFilter (org.activityinfo.server.command.QueryFilter)1 Activity (org.activityinfo.store.mysql.metadata.Activity)1 LinkedActivity (org.activityinfo.store.mysql.metadata.LinkedActivity)1