Search in sources :

Example 1 with ServiceDefinition

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());
}
Also used : ServiceDescriptor(com.emc.sa.descriptor.ServiceDescriptor) ServiceField(com.emc.sa.descriptor.ServiceField) ServiceDefinition(com.emc.sa.descriptor.ServiceDefinition)

Example 2 with ServiceDefinition

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);
    }
}
Also used : Stat(org.apache.zookeeper.data.Stat) ServiceDefinition(com.emc.sa.descriptor.ServiceDefinition) IOException(java.io.IOException) HashSet(java.util.HashSet)

Aggregations

ServiceDefinition (com.emc.sa.descriptor.ServiceDefinition)2 ServiceDescriptor (com.emc.sa.descriptor.ServiceDescriptor)1 ServiceField (com.emc.sa.descriptor.ServiceField)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Stat (org.apache.zookeeper.data.Stat)1