Java Code Examples for org.apache.commons.lang.time.StopWatch#stop()

The following examples show how to use org.apache.commons.lang.time.StopWatch#stop() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PooledPBEWithMD5AndDESStringEncryptorThreadedTest.java    From jasypt with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    try {
        
        final int numThreads = Integer.valueOf(args[0]).intValue();
        final int numIters = Integer.valueOf(args[1]).intValue();
        final int poolSize = Integer.valueOf(args[2]).intValue();
        
        PooledPBEWithMD5AndDESStringEncryptorThreadedTest test = 
            new PooledPBEWithMD5AndDESStringEncryptorThreadedTest(numThreads, numIters, poolSize);
        
        System.out.println("Starting test. NumThreads: " + numThreads + " NumIters: " + numIters + " PoolSize: " + poolSize);
        StopWatch sw = new StopWatch();
        sw.start();
        test.testThreadedDigest();
        sw.stop();
        System.out.println("Test finished in: " + sw.toString());
        
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 2
Source File: BaseUpdateChannelCommand.java    From spacewalk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Private helper method to create a new UpdateErrataCacheEvent and publish it to the
 * MessageQueue.
 * @param orgIn The org we're updating.
 */
private void publishUpdateErrataCacheEvent() {
    StopWatch sw = new StopWatch();
    if (log.isDebugEnabled()) {
        log.debug("Updating errata cache");
        sw.start();
    }

    UpdateErrataCacheEvent uece =
        new UpdateErrataCacheEvent(UpdateErrataCacheEvent.TYPE_ORG);
    uece.setOrgId(user.getOrg().getId());
    MessageQueue.publish(uece);

    if (log.isDebugEnabled()) {
        sw.stop();
        log.debug("Finished Updating errata cache. Took [" +
                sw.getTime() + "]");
    }
}
 
Example 3
Source File: ChannelSoftwareHandler.java    From spacewalk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Private helper method to create a new UpdateErrataCacheEvent and publish it to the
 * MessageQueue.
 * @param orgIn The org we're updating.
 */
private void publishUpdateErrataCacheEvent(Org orgIn) {
    StopWatch sw = new StopWatch();
    if (log.isDebugEnabled()) {
        log.debug("Updating errata cache");
        sw.start();
    }

    UpdateErrataCacheEvent uece =
        new UpdateErrataCacheEvent(UpdateErrataCacheEvent.TYPE_ORG);
    uece.setOrgId(orgIn.getId());
    MessageQueue.publish(uece);

    if (log.isDebugEnabled()) {
        sw.stop();
        log.debug("Finished Updating errata cache. Took [" +
                sw.getTime() + "]");
    }
}
 
Example 4
Source File: JdbcEntityReaderImpl.java    From Eagle with Apache License 2.0 6 votes vote down vote up
@Override
public <E> List<E> query(List<String> ids) throws Exception {
    PrimaryKeyCriteriaBuilder criteriaBuilder = new PrimaryKeyCriteriaBuilder(ids,this.jdbcEntityDefinition.getJdbcTableName());
    Criteria criteria = criteriaBuilder.build();
    String displaySql = SqlBuilder.buildQuery(criteria).getDisplayString();
    if(LOG.isDebugEnabled()) LOG.debug("Querying: " + displaySql);
    EntityRecordMapper recordMapper = new EntityRecordMapper(jdbcEntityDefinition);
    final StopWatch stopWatch = new StopWatch();
    List<E> result;
    try {
        stopWatch.start();
        TorqueStatementPeerImpl peer = ConnectionManagerFactory.getInstance().getStatementExecutor();
        result = peer.delegate().doSelect(criteria, recordMapper);
        LOG.info(String.format("Read %s records in %s ms (sql: %s)",result.size(),stopWatch.getTime(),displaySql));
    }catch (Exception ex){
        LOG.error("Failed to query by: "+displaySql+", due to: "+ex.getMessage(),ex);
        throw new IOException("Failed to query by: "+displaySql,ex);
    }finally {
        stopWatch.stop();
    }
    return result;
}
 
Example 5
Source File: StreamWindowBenchmarkTest.java    From eagle with Apache License 2.0 6 votes vote down vote up
private void benchmarkTest(StreamWindow window, StreamWindowRepository.StorageType storageType) {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    LOGGER.info("\n===== Benchmark Test for {} ({}) =====", window.getClass().getSimpleName(), storageType);
    metricReporter.report();
    sendDESCOrderedEventsToWindow(window, storageType, 1000);
    metricReporter.report();
    sendDESCOrderedEventsToWindow(window, storageType, 10000);
    metricReporter.report();
    sendDESCOrderedEventsToWindow(window, storageType, 100000);
    metricReporter.report();
    sendDESCOrderedEventsToWindow(window, storageType, 1000000);
    metricReporter.report();
    stopWatch.stop();
    LOGGER.info("\n===== Finished in total {} ms =====\n", stopWatch.getTime());
}
 
Example 6
Source File: EsServiceMappingStore.java    From soundwave with Apache License 2.0 6 votes vote down vote up
public List<EsServiceMapping> getServiceMappings() throws Exception {
  StopWatch sw = new StopWatch();
  sw.start();
  List<EsServiceMapping> ret = new ArrayList<>();
  SearchResponse result = getByDocType(10000);
  for (SearchHit hit : result.getHits()) {
    try {
      EsServiceMapping
          serviceMapping =
          mapper.readValue(hit.getSourceAsString(), EsServiceMapping.class);
      serviceMapping.buildMatchPatterns();
      ret.add(serviceMapping);
    } catch (Exception ex) {
      logger.error("Cannot create Service mapping from {}", hit.getSourceAsString());
    }
  }
  sw.stop();
  logger.info("Refresh all service mappings in {} ms", sw.getTime());
  return ret;
}
 
Example 7
Source File: CacheService.java    From SkyEye with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 将数据库中的配置表进行缓存
 */
private void loadCache() {
    StopWatch sw = new StopWatch();
    sw.start();
    LOGGER.info("start load config to cache");

    Iterable<ServiceInfo> serviceInfos = this.serviceInfoRepository.findAll();

    for (Iterator<ServiceInfo> it = serviceInfos.iterator(); it.hasNext();) {
        ServiceInfo serviceInfo = it.next();
        this.setOps.add(SERVICE_INFO_PREFIX, serviceInfo.getSid());
    }

    sw.stop();
    LOGGER.info("load config to cache end, cost {} ms", sw.getTime());
}
 
Example 8
Source File: FbRunner.java    From freebencher with Apache License 2.0 6 votes vote down vote up
private void doIt() {
	boolean successful = false;

	StopWatch stopWatch = new StopWatch();
	stopWatch.start();
	try {
		successful = job.getTarget().invoke();
	} catch (Exception e) {
		successful = false;
	}
	stopWatch.stop();
	if (successful) {
		job.getResult().getSuccessfulTests().incrementAndGet();
	} else {
		job.getResult().getFailedTests().incrementAndGet();
	}

	job.getResult()
			.addSingleTestResult(successful, stopWatch.getTime());
	int results = job.getResult().getNumOfTests();
	if (results != 0 && !job.getOptions().isQuiet()
			&& (job.getResult().getNumOfTests() % 100 == 0)) {
		System.err.printf("%d/%d are done\n", results, job.getOptions()
				.getNumOfTests());
	}
}
 
Example 9
Source File: JdbcEntityReaderImpl.java    From eagle with Apache License 2.0 6 votes vote down vote up
@Override
public <E> List<E> query(List<String> ids) throws Exception {
    PrimaryKeyCriteriaBuilder criteriaBuilder = new PrimaryKeyCriteriaBuilder(ids,this.jdbcEntityDefinition.getJdbcTableName());
    Criteria criteria = criteriaBuilder.build();
    String displaySql = SqlBuilder.buildQuery(criteria).getDisplayString();
    if(LOG.isDebugEnabled()) LOG.debug("Querying: " + displaySql);
    EntityRecordMapper recordMapper = new EntityRecordMapper(jdbcEntityDefinition);
    final StopWatch stopWatch = new StopWatch();
    List<E> result;
    try {
        stopWatch.start();
        TorqueStatementPeerImpl peer = ConnectionManagerFactory.getInstance().getStatementExecutor();
        criteria.addSelectColumn(new ColumnImpl(jdbcEntityDefinition.getJdbcTableName(),"*"));
        result = peer.delegate().doSelect(criteria, recordMapper);
        LOG.info(String.format("Read %s records in %s ms (sql: %s)",result.size(),stopWatch.getTime(),displaySql));
    }catch (Exception ex){
        LOG.error("Failed to query by: "+displaySql+", due to: "+ex.getMessage(),ex);
        throw new IOException("Failed to query by: "+displaySql,ex);
    }finally {
        stopWatch.stop();
    }
    return result;
}
 
Example 10
Source File: StreamWindowBenchmarkTest.java    From eagle with Apache License 2.0 6 votes vote down vote up
public void sendDESCOrderedEventsToWindow(StreamWindow window, StreamWindowRepository.StorageType storageType, int num) {
    LOGGER.info("Sending {} events to {} ({})", num, window.getClass().getSimpleName(), storageType);
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    int i = 0;
    while (i < num) {
        PartitionedEvent event = MockSampleMetadataFactory.createPartitionedEventGroupedByName("sampleStream_1", (window.startTime() + i));
        window.add(event);
        i++;
    }
    stopWatch.stop();
    performanceReport.put(num + "\tInsertTime\t" + storageType, stopWatch.getTime());
    LOGGER.info("Inserted {} events in {} ms", num, stopWatch.getTime());
    stopWatch.reset();
    stopWatch.start();
    window.flush();
    stopWatch.stop();
    performanceReport.put(num + "\tReadTime\t" + storageType, stopWatch.getTime());
}
 
Example 11
Source File: GenericEntityServiceResource.java    From eagle with Apache License 2.0 5 votes vote down vote up
public GenericServiceAPIResponseEntity updateDatabase(Statement<ModifyResult<String>> statement) {
    GenericServiceAPIResponseEntity<String> response = new GenericServiceAPIResponseEntity<>();
    Map<String,Object> meta = new HashMap<>();
    StopWatch stopWatch = new StopWatch();

    try {
        stopWatch.start();
        DataStorage dataStorage = DataStorageManager.getDataStorageByEagleConfig();
        if(dataStorage == null){
            LOG.error("Data storage is null");
            throw new IllegalDataStorageException("Data storage is null");
        }
        ModifyResult<String> result = statement.execute(dataStorage);
        if(result.isSuccess()) {
            List<String> keys =result.getIdentifiers();
            if(keys != null) {
                response.setObj(keys, String.class);
                meta.put(TOTAL_RESULTS, keys.size());
            } else {
                meta.put(TOTAL_RESULTS, 0);
            }
            meta.put(ELAPSEDMS,stopWatch.getTime());
            response.setMeta(meta);
            response.setSuccess(true);
        }
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        response.setException(e);
    }finally {
        stopWatch.stop();
    }
    return response;
}
 
Example 12
Source File: MRHistoryJobDailyReporter.java    From eagle with Apache License 2.0 5 votes vote down vote up
private Map<String, Object> buildAlertData(String site, long startTime, long endTime) {
    StopWatch watch = new StopWatch();
    Map<String, Object> data = new HashMap<>();
    this.client = new EagleServiceClientImpl(config);
    String startTimeStr = DateTimeUtil.millisecondsToHumanDateWithSeconds(startTime);
    String endTimeStr = DateTimeUtil.millisecondsToHumanDateWithSeconds(endTime);
    LOG.info("Going to report job summery info for site {} from {} to {}", site, startTimeStr, endTimeStr);
    try {
        watch.start();
        data.putAll(buildJobSummery(site, startTime, endTime));
        data.put(NUM_TOP_USERS_KEY, numTopUsers);
        data.put(JOB_OVERTIME_LIMIT_KEY, jobOvertimeLimit);
        data.put(ALERT_TITLE_KEY, String.format("[%s] Job Report for 12 Hours", site.toUpperCase()));
        data.put(REPORT_RANGE_KEY, String.format("%s ~ %s %s", startTimeStr, endTimeStr, DateTimeUtil.CURRENT_TIME_ZONE.getID()));
        data.put(EAGLE_JOB_LINK_KEY, String.format("http://%s:%d/#/site/%s/jpm/list?startTime=%s&endTime=%s",
                config.getString(SERVICE_HOST), config.getInt(SERVICE_PORT), site, startTimeStr, endTimeStr));
        watch.stop();
        LOG.info("Fetching DailyJobReport tasks {} seconds", watch.getTime() / DateTimeUtil.ONESECOND);
    } finally {
        try {
            client.close();
        } catch (IOException e) {
            LOG.info("fail to close eagle service client");
        }
    }
    return data;
}
 
Example 13
Source File: LargeInputFileIT.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@Test
public void testLargeFile() throws Exception {
  File inputFile = new File(getInputDir(), "input.avro");
  File outputFile = new File(getOutputDir(), "input.parquet");
  long recordCount = Long.valueOf(System.getProperty(TARGET_RECORD_COUNT, TARGET_RECORD_COUNT_DEFAULT));
  StopWatch stopWatch = new StopWatch();

  stopWatch.start();
  generateAvroFile(AVRO_SCHEMA, inputFile, recordCount);
  stopWatch.stop();

  LOG.info("Created input avro file in {}, contains {} records and have {}.", stopWatch.toString(), recordCount, humanReadableSize(inputFile.length()));


  AvroConversionCommonConfig commonConfig = new AvroConversionCommonConfig();
  AvroParquetConfig conf = new AvroParquetConfig();
  commonConfig.inputFile = inputFile.getAbsolutePath();
  commonConfig.outputDirectory = getOutputDir();

  MapReduceExecutor executor = generateExecutor(commonConfig, conf, Collections.emptyMap());

  ExecutorRunner runner = new ExecutorRunner.Builder(MapReduceDExecutor.class, executor)
    .setOnRecordError(OnRecordError.TO_ERROR)
    .build();
  runner.runInit();

  Record record = RecordCreator.create();
  record.set(Field.create(Collections.<String, Field>emptyMap()));

  stopWatch.reset();
  stopWatch.start();
  runner.runWrite(ImmutableList.of(record));
  stopWatch.stop();
  LOG.info("Generated output parquet file in {} and have {}.", stopWatch.toString(), humanReadableSize(outputFile.length()));

  Assert.assertEquals(0, runner.getErrorRecords().size());
  runner.runDestroy();

  validateParquetFile(new Path(outputFile.getAbsolutePath()), recordCount);
}
 
Example 14
Source File: GenericEntityServiceResource.java    From eagle with Apache License 2.0 4 votes vote down vote up
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public GenericServiceAPIResponseEntity update(InputStream inputStream,
                                             @QueryParam("serviceName") String serviceName){
    GenericServiceAPIResponseEntity<String> response = new GenericServiceAPIResponseEntity<String>();
    DataStorage dataStorage;
    Map<String,Object> meta = new HashMap<>();
    StopWatch stopWatch = new StopWatch();
    try {
        stopWatch.start();
        EntityDefinition entityDefinition = EntityDefinitionManager.getEntityByServiceName(serviceName);

        if(entityDefinition == null){
            throw new IllegalArgumentException("entity definition of service "+serviceName+" not found");
        }

        List<? extends TaggedLogAPIEntity> entities = unmarshalEntitiesByServie(inputStream, entityDefinition);
        dataStorage = DataStorageManager.getDataStorageByEagleConfig();

        UpdateStatement updateStatement = new UpdateStatement(entities,entityDefinition);
        ModifyResult<String> result = updateStatement.execute(dataStorage);
        if(result.isSuccess()) {
            List<String> keys =result.getIdentifiers();
            if(keys != null) {
                response.setObj(keys, String.class);
                meta.put(TOTAL_RESULTS,keys.size());
            }else{
                meta.put(TOTAL_RESULTS,0);
            }
            meta.put(ELAPSEDMS,stopWatch.getTime());
            response.setMeta(meta);
            response.setSuccess(true);
        }
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        response.setException(e);
    } finally {
        stopWatch.stop();
    }
    return response;
}
 
Example 15
Source File: GenericEntityServiceResource.java    From eagle with Apache License 2.0 4 votes vote down vote up
@PUT
@Consumes({MediaType.MULTIPART_FORM_DATA})
@Produces(MediaType.APPLICATION_JSON)
public GenericServiceAPIResponseEntity update(@FormDataParam("file") InputStream fileInputStream,
                                              @FormDataParam("file") FormDataContentDisposition cdh,
                                              @QueryParam("serviceName") String serviceName){
    GenericServiceAPIResponseEntity<String> response = new GenericServiceAPIResponseEntity<String>();
    DataStorage dataStorage;
    Map<String,Object> meta = new HashMap<>();
    StopWatch stopWatch = new StopWatch();
    try {
        stopWatch.start();
        EntityDefinition entityDefinition = EntityDefinitionManager.getEntityByServiceName(serviceName);

        if(entityDefinition == null){
            throw new IllegalArgumentException("entity definition of service "+serviceName+" not found");
        }

        List<? extends TaggedLogAPIEntity> entities = unmarshalEntitiesByServie(fileInputStream, entityDefinition);
        dataStorage = DataStorageManager.getDataStorageByEagleConfig();

        UpdateStatement updateStatement = new UpdateStatement(entities,entityDefinition);
        ModifyResult<String> result = updateStatement.execute(dataStorage);
        if(result.isSuccess()) {
            List<String> keys =result.getIdentifiers();
            if(keys != null) {
                response.setObj(keys, String.class);
                meta.put(TOTAL_RESULTS,keys.size());
            }else{
                meta.put(TOTAL_RESULTS,0);
            }
            meta.put(ELAPSEDMS,stopWatch.getTime());
            response.setMeta(meta);
            response.setSuccess(true);
        }
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        response.setException(e);
    } finally {
        stopWatch.stop();
    }
    return response;
}
 
Example 16
Source File: NavTest.java    From spacewalk with GNU General Public License v2.0 4 votes vote down vote up
public void testDigester() throws Exception {
    StopWatch st = new StopWatch();
    st.start();
    NavTree nt =
        NavDigester.buildTree(TestUtils.findTestData("sitenav.xml"));
    assertTrue(nt.getTitleDepth() == 0);
    assertTrue(nt.getLabel().equals("sitenav_unauth"));
    assertNotNull(nt.getAclMixins());

    NavTreeIndex nti = new NavTreeIndex(nt);

    String testPath = "/rhn/help/index.do";
    nti.computeActiveNodes(testPath, null);

    NavNode bestNode = nti.getBestNode();
    assertEquals(bestNode.getName(), "Help Desk");
    assertEquals(bestNode.getPrimaryURL(), testPath);

    log.info("Index Duration: " +
                   st.getTime() / 1000f + " seconds");

    RenderEngine nr = new RenderEngine(nti);
    st.stop();

    Renderable[] renderers = new Renderable[3];

    renderers[0] = new SidenavRenderer();

    renderers[1] = new TopnavRenderer();
    renderers[1].setRenderGuard(new DepthGuard(0, 0));

    renderers[2] = new TextRenderer();
    renderers[2].setRenderGuard(new DepthGuard(1, Integer.MAX_VALUE));

    for (int i = 0; i < renderers.length; i++) {
        log.info("Using Renderable " +
                       renderers[i].getClass() + ":\n" +
                       nr.render(renderers[i]));
    }

    log.info("Parse Duration: " +
                   st.getTime() / 1000f + " seconds");

}
 
Example 17
Source File: GenericEntityServiceResource.java    From eagle with Apache License 2.0 4 votes vote down vote up
/**
 *
 * Delete by entity lists
 *
 * Use "POST /entities/delete" instead of "DELETE  /entities" to walk around jersey DELETE issue for request with body
 *
 * @param inputStream
 * @param serviceName
 * @return
 */
@POST
@Path(DELETE_ENTITIES_PATH)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public GenericServiceAPIResponseEntity deleteEntities(InputStream inputStream,
                                             @QueryParam("serviceName") String serviceName,
                                             @QueryParam("byId") Boolean deleteById){
    GenericServiceAPIResponseEntity<String> response = new GenericServiceAPIResponseEntity<String>();
    DataStorage dataStorage = null;
    Map<String,Object> meta = new HashMap<String, Object>();

    if(deleteById == null) deleteById = false;

    StopWatch stopWatch = new StopWatch();

    try {
        stopWatch.start();
        dataStorage = DataStorageManager.getDataStorageByEagleConfig();
        DeleteStatement statement = new DeleteStatement(serviceName);

        if(deleteById) {
            LOG.info("Deleting "+serviceName+" by ids");
            List<String> deleteIds = unmarshalAsStringlist(inputStream);
            statement.setIds(deleteIds);
        }else {
            LOG.info("Deleting "+serviceName+" by entities");
            EntityDefinition entityDefinition = EntityDefinitionManager.getEntityByServiceName(serviceName);
            if (entityDefinition == null) {
                throw new IllegalArgumentException("Entity definition of service " + serviceName + " not found");
            }
            List<? extends TaggedLogAPIEntity> entities = unmarshalEntitiesByServie(inputStream, entityDefinition);
            statement.setEntities(entities);
        }

        ModifyResult<String> result = statement.execute(dataStorage);
        if (result.isSuccess()) {
            List<String> keys = result.getIdentifiers();
            if (keys != null) {
                response.setObj(keys, String.class);
                meta.put(TOTAL_RESULTS, keys.size());
            } else {
                meta.put(TOTAL_RESULTS, 0);
            }
            meta.put(ELAPSEDMS, stopWatch.getTime());
            response.setMeta(meta);
            response.setSuccess(true);
        }
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        response.setException(e);
    }finally {
        stopWatch.stop();
    }
    return response;
}
 
Example 18
Source File: Ec2InstanceUpdateHandler.java    From soundwave with Apache License 2.0 4 votes vote down vote up
private MessageProcessingResult ensureInstanceCreated(NotificationEvent event) throws Exception {

    String instanceId = event.getDetail().getInstanceId();
    StopWatch watch = new StopWatch();
    watch.start();
    MessageProcessingResult result = new MessageProcessingResult(event);
    result.setSucceed(true);
    try {
      //Get EC2 instance
      Instance inst = cloudInstanceStore.getInstance(instanceId);

      if (inst != null) {
        //Create the corresponding EsInstance
        EsInstance esInstance = esInstanceFactory.createFromEC2(inst);

        long version = cmdbInstanceStore.updateOrInsertInstance(esInstance);
        if (version == 0) {
          logger.info("Instance {} is created", instanceId);
          //Created in ES
          DateTime utcNow = DateTime.now(DateTimeZone.UTC);
          DateTime enqueueTime = new DateTime(event.getSqsSentTime(), DateTimeZone.UTC);

          int sinceEnqueued = Seconds.secondsBetween(enqueueTime, utcNow).getSeconds();
          int
              sinceLaunched =
              Seconds.secondsBetween(new DateTime(esInstance.getAwsLaunchTime()), utcNow)
                  .getSeconds();

          //First time instance created
          Stats.addMetric(StatsUtil.getStatsName("ec2_creation", "since_enqueued"),
              sinceEnqueued > 0 ? sinceEnqueued : 0);

          Stats.addMetric(StatsUtil.getStatsName("ec2_creation", "since_launched"),
              sinceLaunched > 0 ? sinceLaunched : 0);
        } else {
          logger.info("Instance {} is updated", instanceId);
        }

        logger.info("Create Instance {} in ElasticSearch", instanceId);
        onInstanceCreation(esInstance, result);
        Tag nameTag = AwsUtilities.getAwsTag(inst, "Name");
        if (nameTag == null) {
          result.setError(MessageProcessingResult.MessageProcessingError.NO_NAME_TAG);
        } else if (State.PENDING.name().equalsIgnoreCase(esInstance.getState())) {
          //Still pending. Put back to the queue and wait it into running
          result.setError(MessageProcessingResult.MessageProcessingError.STILL_PENDING);
        } else {
          onInstanceCreation(esInstance, result);
        }
        try {
          syncWithDailySnapshot(event, esInstance);
        } catch (Exception ex) {
          logger.error("Failed to sync with daily snapshot {} with error {}", instanceId,
              ex.getMessage());
        }

      } else {
        result.setError(MessageProcessingResult.MessageProcessingError.NOT_EXIST_IN_EC_2);
      }
      return result;
    } finally {
      watch.stop();
      result.setDuration(watch.getTime());
    }
  }
 
Example 19
Source File: SuggestionServiceImpl.java    From intellij-spring-assistant with MIT License 4 votes vote down vote up
private List<LookupElementBuilder> doFindSuggestionsForQueryPrefix(Module module,
    Trie<String, MetadataSuggestionNode> rootSearchIndex, FileType fileType, PsiElement element,
    @Nullable List<String> ancestralKeys, String queryWithDotDelimitedPrefixes,
    @Nullable Set<String> siblingsToExclude) {
  debug(() -> log.debug("Search requested for " + queryWithDotDelimitedPrefixes));
  StopWatch timer = new StopWatch();
  timer.start();
  try {
    String[] querySegmentPrefixes = toSanitizedPathSegments(queryWithDotDelimitedPrefixes);
    Set<Suggestion> suggestions = null;
    if (ancestralKeys != null) {
      String[] ancestralKeySegments =
          ancestralKeys.stream().flatMap(key -> stream(toRawPathSegments(key)))
              .toArray(String[]::new);
      MetadataSuggestionNode rootNode = rootSearchIndex.get(sanitise(ancestralKeySegments[0]));
      if (rootNode != null) {
        List<SuggestionNode> matchesRootToDeepest;
        SuggestionNode startSearchFrom = null;
        if (ancestralKeySegments.length > 1) {
          String[] sanitisedAncestralPathSegments =
              stream(ancestralKeySegments).map(SuggestionNode::sanitise).toArray(String[]::new);
          matchesRootToDeepest = rootNode
              .findDeepestSuggestionNode(module, modifiableList(rootNode),
                  sanitisedAncestralPathSegments, 1);
          if (matchesRootToDeepest != null && matchesRootToDeepest.size() != 0) {
            startSearchFrom = matchesRootToDeepest.get(matchesRootToDeepest.size() - 1);
          }
        } else {
          startSearchFrom = rootNode;
          matchesRootToDeepest = singletonList(rootNode);
        }

        if (startSearchFrom != null) {
          // if search start node is a leaf, this means, the user is looking for values for the given key, lets find the suggestions for values
          if (startSearchFrom.isLeaf(module)) {
            suggestions = startSearchFrom.findValueSuggestionsForPrefix(module, fileType,
                unmodifiableList(matchesRootToDeepest),
                sanitise(truncateIdeaDummyIdentifier(element.getText())), siblingsToExclude);
          } else {
            suggestions = startSearchFrom.findKeySuggestionsForQueryPrefix(module, fileType,
                unmodifiableList(matchesRootToDeepest), matchesRootToDeepest.size(),
                querySegmentPrefixes, 0, siblingsToExclude);
          }
        }
      }
    } else {
      String rootQuerySegmentPrefix = querySegmentPrefixes[0];
      SortedMap<String, MetadataSuggestionNode> topLevelQueryResults =
          rootSearchIndex.prefixMap(rootQuerySegmentPrefix);

      Collection<MetadataSuggestionNode> childNodes;
      int querySegmentPrefixStartIndex;

      // If no results are found at the top level, let dive deeper and find matches
      if (topLevelQueryResults == null || topLevelQueryResults.size() == 0) {
        childNodes = rootSearchIndex.values();
        querySegmentPrefixStartIndex = 0;
      } else {
        childNodes = topLevelQueryResults.values();
        querySegmentPrefixStartIndex = 1;
      }

      Collection<MetadataSuggestionNode> nodesToSearchAgainst;
      if (siblingsToExclude != null) {
        Set<MetadataSuggestionNode> nodesToExclude = siblingsToExclude.stream()
            .flatMap(exclude -> rootSearchIndex.prefixMap(exclude).values().stream())
            .collect(toSet());
        nodesToSearchAgainst =
            childNodes.stream().filter(node -> !nodesToExclude.contains(node)).collect(toList());
      } else {
        nodesToSearchAgainst = childNodes;
      }

      suggestions = doFindSuggestionsForQueryPrefix(module, fileType, nodesToSearchAgainst,
          querySegmentPrefixes, querySegmentPrefixStartIndex);
    }

    if (suggestions != null) {
      return toLookupElementBuilders(suggestions);
    }
    return null;
  } finally {
    timer.stop();
    debug(() -> log.debug("Search took " + timer.toString()));
  }
}
 
Example 20
Source File: GenericEntityServiceResource.java    From eagle with Apache License 2.0 4 votes vote down vote up
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public GenericServiceAPIResponseEntity create(InputStream inputStream,
                                             @QueryParam("serviceName") String serviceName){
    GenericServiceAPIResponseEntity<String> response = new GenericServiceAPIResponseEntity<String>();
    Map<String,Object> meta = new HashMap<>();
    StopWatch stopWatch = new StopWatch();
    try {
        stopWatch.start();
        EntityDefinition entityDefinition = EntityDefinitionManager.getEntityByServiceName(serviceName);

        if(entityDefinition == null){
            throw new IllegalArgumentException("entity definition of service "+serviceName+" not found");
        }

        List<? extends TaggedLogAPIEntity> entities = unmarshalEntitiesByServie(inputStream, entityDefinition);
        DataStorage dataStorage = DataStorageManager.getDataStorageByEagleConfig();
        CreateStatement createStatement = new CreateStatement(entities,entityDefinition);
        ModifyResult<String> result = createStatement.execute(dataStorage);
        if(result.isSuccess()) {
            List<String> keys =result.getIdentifiers();
            if(keys != null) {
                response.setObj(keys, String.class);
                response.setObj(keys, String.class);
                meta.put(TOTAL_RESULTS,keys.size());
            }else{
                meta.put(TOTAL_RESULTS,0);
            }
            meta.put(ELAPSEDMS,stopWatch.getTime());
            response.setMeta(meta);
            response.setSuccess(true);
        }
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        response.setException(e);
    }finally {
        stopWatch.stop();
    }
    return response;
}