InstanceProviderManager { InstanceProvider getClassProvider(String className, String providerName, HostnameResolver hostnameResolver) { final String classKey = className + "-" + providerName; InstanceProvider provider = providerMap.get(classKey); if (provider != null) { return provider; } Class<?> instanceClass; try { instanceClass = Class.forName(className); } catch (ClassNotFoundException e) { LOGGER.error("getClassInstance: Provider class {} not found", className); return null; } try { provider = (InstanceProvider) instanceClass.newInstance(); } catch (InstantiationException | IllegalAccessException ex) { LOGGER.error("getClassInstance: Unable to get new instance for provider {} error {}", className, ex.getMessage()); return null; } provider.initialize(providerName, className, sslContext, keyStore); provider.setHostnameResolver(hostnameResolver); providerMap.put(classKey, provider); return provider; } InstanceProviderManager(DataStore dataStore, SSLContext sslContext, KeyStore keyStore);   }
@Test public void testGetClassProvider() { SignedDomain signedDomain = createSignedDomainClassEndpoint("coretech", "weather", true, true); store.processDomain(signedDomain, false); InstanceProviderManager provider = new InstanceProviderManager(store, null, null); InstanceProvider client = provider.getProvider("coretech.weather", new HostnameResolver(){}); assertNotNull(client); client.close(); }
@Test public void testGetClassInstance() { HostnameResolver hostnameResolver = new HostnameResolver(){}; InstanceProviderManager providerManager = new InstanceProviderManager(null, null, null); InstanceProvider provider = providerManager.getClassProvider("unknown.class", "provider", hostnameResolver); assertNull(provider); provider = providerManager.getClassProvider("com.yahoo.athenz.instance.provider.impl.InstanceAWSProvider", "provider", hostnameResolver); assertNotNull(provider); provider = providerManager.getClassProvider("com.yahoo.athenz.instance.provider.impl.InstanceAWSECSProvider", "provider", hostnameResolver); assertNotNull(provider); provider = providerManager.getClassProvider("com.yahoo.athenz.instance.provider.impl.InstanceAWSLambdaProvider", "provider", hostnameResolver); assertNotNull(provider); provider = providerManager.getClassProvider("com.yahoo.athenz.instance.provider.impl.InstanceAWSProvider", "provider", hostnameResolver); assertNotNull(provider); provider = providerManager.getClassProvider("com.yahoo.athenz.unknown.class", "provider", hostnameResolver); assertNull(provider); try { providerManager.getClassProvider("com.yahoo.athenz.zts.ZTSConsts", "provider", hostnameResolver); fail(); } catch (Exception ignored) { } }