public String getName() {
return "Chef Service Factory";
}
public void updated(String pid, Dictionary properties) throws ConfigurationException {
ServiceRegistration newRegistration = null;
try {
if (properties != null) {
Properties props = new Properties();
for (Enumeration e = properties.keys(); e.hasMoreElements(); ) {
Object key = e.nextElement();
Object val = properties.get(key);
props.put(key, val);
}
String api = (String) properties.get(ChefConstants.API);
ProviderMetadata providerMetadata = null;
ApiMetadata apiMetadata = null;
if (!Strings.isNullOrEmpty(api) && installedApis.containsKey(api)) {
apiMetadata = installedApis.get(api);
validate(apiMetadata, properties);
} else {
if (!Strings.isNullOrEmpty(api)) {
apiPids.put(api, pid);
}
pendingPids.put(pid, properties);
LOGGER.warn("Api {} is not currently installed. Service will resume once the the api is installed.", api);
return;
}
String id = (String) properties.get(ChefConstants.NAME);
String clientName = (String) properties.get(ChefConstants.CLIENT_NAME);
String clientKeyFile = (String) properties.get(ChefConstants.CLIENT_KEY_FILE);
String clientCredential = (String) properties.get(ChefConstants.CLIENT_CREDENTIAL);
String validatorName = (String) properties.get(ChefConstants.VALIDATOR_NAME);
String validatorKeyFile = (String) properties.get(ChefConstants.VALIDATOR_KEY_FILE);
String validatorCredential = (String) properties.get(ChefConstants.VALIDATOR_CREDENTIAL);
String endpoint = (String) properties.get(ChefConstants.ENDPOINT);
ChefService service = ChefHelper.createChefService(apiMetadata, id, clientName, clientCredential, clientKeyFile, validatorName, validatorCredential, validatorKeyFile, endpoint);
newRegistration = bundleContext.registerService(
ChefService.class.getName(), service, properties);
//If all goes well remove the pending pid.
if (pendingPids.containsKey(pid)) {
activePids.put(pid, pendingPids.remove(pid));
}
}
} catch (InvalidConfigurationException ex) {
LOGGER.warn("Invalid configuration: {}", ex.getMessage());
} catch (Exception ex) {
LOGGER.error("Error creating compute service.", ex);
} finally {
ServiceRegistration oldRegistration = (newRegistration == null)
? registrations.remove(pid)
: registrations.put(pid, newRegistration);
if (oldRegistration != null) {
oldRegistration.unregister();
}
}
}