use of com.emc.sa.descriptor.ServiceDefinition in project coprhd-controller by CoprHD.
the class ServiceDescriptorTests method testLoadingAndRetrieving.
@Test
public void testLoadingAndRetrieving() throws Exception {
ZkServiceDescriptors serviceDescriptors = new ZkServiceDescriptors();
serviceDescriptors.setCoordinatorClient(coordinatorService.getCoordinatorClient());
serviceDescriptors.start();
List<ServiceDefinition> services = ServiceDefinitionLoader.load(ServiceDescriptorTests.class.getClassLoader());
Assert.assertEquals(1, services.size());
serviceDescriptors.addServices(services);
ServiceDescriptor descriptor = serviceDescriptors.getDescriptor(Locale.getDefault(), "TestService");
Assert.assertNotNull(descriptor);
Assert.assertEquals("TestService", descriptor.getServiceId());
List<ServiceField> fields = descriptor.getFieldList();
Assert.assertEquals(3, fields.size());
Assert.assertEquals("project", fields.get(0).getName());
Assert.assertEquals("Project", fields.get(0).getLabel());
}
use of com.emc.sa.descriptor.ServiceDefinition in project coprhd-controller by CoprHD.
the class ZkServiceDescriptors method addServices.
/**
* Adds all the given service definitions to the Zookeeper tree
*/
public void addServices(List<ServiceDefinition> services) throws Exception {
ensurePathExists();
Set<String> remainingDescriptors = new HashSet<>(dataManager.getChildren(ZK_SERVICE_DEFINITION_PATH));
for (ServiceDefinition service : services) {
LOG.debug(String.format("Adding Service %s into ZK", service.serviceId));
String path = getServiceDefinitionPath(service.serviceId);
try {
Stat before = dataManager.checkExists(path);
dataManager.putData(path, service);
Stat after = dataManager.checkExists(path);
nodeUpdated(path, before, after);
// Remove the service from the remaining list
remainingDescriptors.remove(service.serviceId);
} catch (Exception e) {
LOG.error(String.format("Failed to add Service %s into ZK, path: %s", service.serviceId, path), e);
throw e;
}
}
// Remove any remaining descriptors
for (String descriptorName : remainingDescriptors) {
LOG.info(String.format("Removing old Service %s from ZK", descriptorName));
dataManager.removeNode(ZK_SERVICE_DEFINITION_PATH + "/" + descriptorName);
}
}
Aggregations