@Test public void testMetricsLoaded() throws Exception { URL rootDirectoryURL = StackManagerTest.class.getResource("/"); Assert.notNull(rootDirectoryURL); File resourcesDirectory = new File(new File(rootDirectoryURL.getFile()).getParentFile().getParentFile(), "src/main/resources"); File stackRoot = new File(resourcesDirectory, "stacks"); File commonServices = new File(resourcesDirectory, "common-services"); File extensions = null; try { URL extensionsURL = ClassLoader.getSystemClassLoader().getResource("extensions"); if (extensionsURL != null) { extensions = new File(extensionsURL.getPath().replace("test-classes","classes")); } } catch (Exception e) {} MetainfoDAO metaInfoDao = createNiceMock(MetainfoDAO.class); StackDAO stackDao = createNiceMock(StackDAO.class); ExtensionDAO extensionDao = createNiceMock(ExtensionDAO.class); ExtensionLinkDAO linkDao = createNiceMock(ExtensionLinkDAO.class); ActionMetadata actionMetadata = createNiceMock(ActionMetadata.class); Configuration config = createNiceMock(Configuration.class); ExtensionEntity extensionEntity = createNiceMock(ExtensionEntity.class); expect(config.getSharedResourcesDirPath()).andReturn( ClassLoader.getSystemClassLoader().getResource("").getPath()).anyTimes(); expect( extensionDao.find(EasyMock.anyObject(String.class), EasyMock.anyObject(String.class))).andReturn(extensionEntity).atLeastOnce(); List<ExtensionLinkEntity> list = Collections.emptyList(); expect( linkDao.findByStack(EasyMock.anyObject(String.class), EasyMock.anyObject(String.class))).andReturn(list).atLeastOnce(); replay(config, metaInfoDao, stackDao, extensionDao, linkDao, actionMetadata); OsFamily osFamily = new OsFamily(config); StackManager stackManager = new StackManager(stackRoot, commonServices, extensions, osFamily, false, metaInfoDao, actionMetadata, stackDao, extensionDao, linkDao); for (StackInfo stackInfo : stackManager.getStacks()) { for (ServiceInfo serviceInfo : stackInfo.getServices()) { Type type = new TypeToken<Map<String, Map<String, List<MetricDefinition>>>>() { }.getType(); Gson gson = new Gson(); Map<String, Map<String, List<MetricDefinition>>> map = null; if (serviceInfo.getMetricsFile() != null) { try { map = gson.fromJson(new FileReader(serviceInfo.getMetricsFile()), type); } catch (Exception e) { e.printStackTrace(); throw new AmbariException("Failed to load metrics from file " + serviceInfo.getMetricsFile().getAbsolutePath()); } } } } }
public Collection<StackInfo> getStacks(String name) { Collection<StackInfo> stacks = new HashSet<StackInfo>(); for (StackInfo stack: stackMap.values()) { if (stack.getName().equals(name)) { stacks.add(stack); } } return stacks; }
StackManager { public Collection<StackInfo> getStacks(String name) { Collection<StackInfo> stacks = new HashSet<StackInfo>(); for (StackInfo stack: stackMap.values()) { if (stack.getName().equals(name)) { stacks.add(stack); } } return stacks; } }
StackManager { public Collection<StackInfo> getStacks(String name) { Collection<StackInfo> stacks = new HashSet<StackInfo>(); for (StackInfo stack: stackMap.values()) { if (stack.getName().equals(name)) { stacks.add(stack); } } return stacks; } @AssistedInject  StackManager(@Assisted("stackRoot") File stackRoot,
      @Assisted("commonServicesRoot") @Nullable File commonServicesRoot,
      @Assisted("extensionRoot") @Nullable File extensionRoot,
      @Assisted OsFamily osFamily, @Assisted boolean validate,
      MetainfoDAO metaInfoDAO, ActionMetadata actionMetadata, StackDAO stackDao,
      ExtensionDAO extensionDao, ExtensionLinkDAO linkDao); }
StackManager { public Collection<StackInfo> getStacks(String name) { Collection<StackInfo> stacks = new HashSet<StackInfo>(); for (StackInfo stack: stackMap.values()) { if (stack.getName().equals(name)) { stacks.add(stack); } } return stacks; } @AssistedInject  StackManager(@Assisted("stackRoot") File stackRoot,
      @Assisted("commonServicesRoot") @Nullable File commonServicesRoot,
      @Assisted("extensionRoot") @Nullable File extensionRoot,
      @Assisted OsFamily osFamily, @Assisted boolean validate,
      MetainfoDAO metaInfoDAO, ActionMetadata actionMetadata, StackDAO stackDao,
      ExtensionDAO extensionDao, ExtensionLinkDAO linkDao); StackInfo getStack(String name, String version); Collection<StackInfo> getStacks(String name); Collection<StackInfo> getStacks(); ExtensionInfo getExtension(String name, String version); Collection<ExtensionInfo> getExtensions(String name); Collection<ExtensionInfo> getExtensions(); boolean haveAllRepoUrlsBeenResolved(); static Validator getPropertySchemaValidator(); static void validateAllPropertyXmlsInFolderRecursively(File stackRoot, Validator validator); void linkStackToExtension(StackInfo stack, ExtensionInfo extension); void unlinkStackAndExtension(StackInfo stack, ExtensionInfo extension); }
StackManager { public Collection<StackInfo> getStacks(String name) { Collection<StackInfo> stacks = new HashSet<StackInfo>(); for (StackInfo stack: stackMap.values()) { if (stack.getName().equals(name)) { stacks.add(stack); } } return stacks; } @AssistedInject  StackManager(@Assisted("stackRoot") File stackRoot,
      @Assisted("commonServicesRoot") @Nullable File commonServicesRoot,
      @Assisted("extensionRoot") @Nullable File extensionRoot,
      @Assisted OsFamily osFamily, @Assisted boolean validate,
      MetainfoDAO metaInfoDAO, ActionMetadata actionMetadata, StackDAO stackDao,
      ExtensionDAO extensionDao, ExtensionLinkDAO linkDao); StackInfo getStack(String name, String version); Collection<StackInfo> getStacks(String name); Collection<StackInfo> getStacks(); ExtensionInfo getExtension(String name, String version); Collection<ExtensionInfo> getExtensions(String name); Collection<ExtensionInfo> getExtensions(); boolean haveAllRepoUrlsBeenResolved(); static Validator getPropertySchemaValidator(); static void validateAllPropertyXmlsInFolderRecursively(File stackRoot, Validator validator); void linkStackToExtension(StackInfo stack, ExtensionInfo extension); void unlinkStackAndExtension(StackInfo stack, ExtensionInfo extension); static final String PROPERTY_SCHEMA_PATH; static String PATH_DELIMITER; static final String COMMON_SERVICES; static final String EXTENSIONS; static final String METAINFO_FILE_NAME; }