Search in sources :

Example 26 with Service

use of com.emc.storageos.coordinator.common.Service in project coprhd-controller by CoprHD.

the class AbstractManager method areAllDbsvcActive.

/**
 * Check if all dbsvc instances are active in the cluster
 * currently it's only being used before adjusting db token number but it might as well be used elsewhere.
 *
 * @return true if all dbsvc are active, false otherwise
 */
protected boolean areAllDbsvcActive() {
    CoordinatorClient coordinatorClient = coordinator.getCoordinatorClient();
    List<Service> activeDbsvcs = coordinatorClient.locateAllSvcsAllVers(Constants.DBSVC_NAME);
    List<String> activeDbsvcIds = new ArrayList<>(activeDbsvcs.size());
    for (Service activeDbsvc : activeDbsvcs) {
        activeDbsvcIds.add(activeDbsvc.getId());
    }
    log.info("List of active dbsvc instances in the cluster: {}, expect {} instances", activeDbsvcIds, nodeCount);
    boolean allActive = activeDbsvcs.size() == nodeCount;
    if (!allActive) {
        log.info("not all dbsvc instances are active. Retrying...");
    }
    return allActive;
}
Also used : ArrayList(java.util.ArrayList) CoordinatorClient(com.emc.storageos.coordinator.client.service.CoordinatorClient) Service(com.emc.storageos.coordinator.common.Service)

Example 27 with Service

use of com.emc.storageos.coordinator.common.Service in project coprhd-controller by CoprHD.

the class OpenSourceLicenseManagerImpl method getControllerCapacity.

/**
 * Gets capacity from controller.
 * List of returned resources include volume, file and free storage pool capacities.
 */
public ManagedResourcesCapacity getControllerCapacity() throws InternalServerErrorException {
    _log.info("Getting controller capacity");
    List<Service> services = _coordinator.locateAllServices(LicenseConstants.API_SVC_LOOKUP_KEY, LicenseConstants.SERVICE_LOOKUP_VERSION, null, null);
    for (Service service : services) {
        try {
            // service could be null, if so get next service.
            if (service != null) {
                return getClient(service).get(SysClientFactory._URI_PROVISIONING_MANAGED_CAPACITY, ManagedResourcesCapacity.class, null);
            }
        } catch (SysClientException exception) {
            _log.error("LicenseManager::getCapacity for Controller. Cannot connect to host: {}", service.getEndpoint().toString());
        }
    }
    // if capacity cannot be retrieved
    _log.error("Controller capacity could not be retrieved");
    throw APIException.internalServerErrors.getObjectError("controller capacity", null);
}
Also used : Service(com.emc.storageos.coordinator.common.Service) SysClientException(com.emc.storageos.systemservices.exceptions.SysClientException)

Example 28 with Service

use of com.emc.storageos.coordinator.common.Service in project coprhd-controller by CoprHD.

the class ClusterNodesUtil method getClusterNodeInfo.

/**
 * Gets a reference to the node connection info for the nodes requested.
 *
 * @param nodeIds List of node ids whose information is returned
 * @return A list containing the connection info for all nodes in the Bourne
 *         cluster.
 * @throws IllegalStateException When an exception occurs trying to get the
 *             cluster nodes.
 */
public static List<NodeInfo> getClusterNodeInfo(List<String> nodeIds) {
    List<NodeInfo> nodeInfoList = new ArrayList<NodeInfo>();
    List<String> validNodeIds = new ArrayList<String>();
    try {
        if (nodeIds != null && !nodeIds.isEmpty()) {
            _log.info("Getting cluster node info for ids: {}", nodeIds);
        } else {
            _log.info("Getting cluster node info for all nodes");
        }
        // We get all instances of the "syssvc" services registered with the
        // cluster coordinator. There will be one on each Bourne cluster
        // node.
        List<Service> svcList = _coordinator.locateAllServices(_service.getName(), _service.getVersion(), null, null);
        for (Service svc : svcList) {
            _log.debug("Got service with node id " + svc.getNodeId());
            // if there are node ids requested
            if (nodeIds != null && !nodeIds.isEmpty() && !nodeIds.contains(svc.getNodeId())) {
                continue;
            }
            // The service identifier specifies the connection information
            // for the node on which the service executes.
            URI nodeEndPoint = svc.getEndpoint(null);
            if (nodeEndPoint != null) {
                nodeInfoList.add(new NodeInfo(svc.getNodeId(), svc.getNodeName(), nodeEndPoint));
                validNodeIds.add(svc.getNodeId());
            }
        }
        _log.debug("Valid node ids: {}", validNodeIds);
    } catch (Exception e) {
        throw APIException.internalServerErrors.getObjectFromError("cluster nodes info", "coordinator", e);
    }
    // validate if all requested node ids information is retrieved
    if (nodeIds != null && !nodeIds.isEmpty() && !validNodeIds.containsAll(nodeIds)) {
        nodeIds.removeAll(validNodeIds);
        throw APIException.badRequests.parameterIsNotValid("node id(s): " + nodeIds);
    }
    return nodeInfoList;
}
Also used : ArrayList(java.util.ArrayList) Service(com.emc.storageos.coordinator.common.Service) URI(java.net.URI) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException)

Example 29 with Service

use of com.emc.storageos.coordinator.common.Service in project coprhd-controller by CoprHD.

the class BeaconTest method testBeacon.

@Test
public void testBeacon() throws Exception {
    final String tag = "foo";
    final String endpointKey = "key";
    DummyServiceImpl service = new DummyServiceImpl(10099, tag, endpointKey);
    service.startRmiServer();
    service.start(1000 * 5);
    Service si = service.getServiceInfo();
    CoordinatorClient client = connectClient();
    DummyService found = client.locateService(DummyService.class, si.getName(), si.getVersion(), tag, endpointKey);
    Assert.assertNotNull(found);
    found.test();
    List<Service> services = client.locateAllServices(si.getName(), si.getVersion(), tag, endpointKey);
    Assert.assertEquals(services.size(), 1);
    Assert.assertEquals(services.get(0).getName(), si.getName());
    Assert.assertEquals(services.get(0).getVersion(), si.getVersion());
    Assert.assertEquals(services.get(0).getEndpoint(), si.getEndpoint());
    Assert.assertTrue(services.get(0).isTagged(tag));
    Assert.assertEquals(services.get(0).getEndpoint(endpointKey), si.getEndpoint());
    try {
        client.locateService(DummyService.class, si.getName(), si.getVersion(), "random", endpointKey);
        assert false;
    } catch (CoordinatorException expected) {
    // ignore this exception since it's expected
    }
    try {
        client.locateService(DummyService.class, si.getName(), si.getVersion(), tag, "random");
        assert false;
    } catch (CoordinatorException expected) {
        _log.info("CoordinatorException is throwed as we expected", expected);
    }
    service.stopRmiServer();
    service.stop();
}
Also used : FatalCoordinatorException(com.emc.storageos.coordinator.exceptions.FatalCoordinatorException) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) Service(com.emc.storageos.coordinator.common.Service) Test(org.junit.Test)

Example 30 with Service

use of com.emc.storageos.coordinator.common.Service in project coprhd-controller by CoprHD.

the class BeaconTest method testRmiFailover.

@Test
public void testRmiFailover() throws Exception {
    final String tag = "foo";
    final String endpointKey = "bar";
    DummyServiceImpl service = new DummyServiceImpl(10100, tag, endpointKey);
    service.startRmiServer();
    service.start(1000 * 10);
    DummyServiceImpl service2 = new DummyServiceImpl(10101, tag, endpointKey);
    service2.startRmiServer();
    service2.start(1000 * 10);
    Service si = service.getServiceInfo();
    CoordinatorClient client = connectClient();
    DummyService found = client.locateService(DummyService.class, si.getName(), si.getVersion(), tag, endpointKey);
    Assert.assertNotNull(found);
    found.test();
    service.stopRmiServer();
    for (int index = 0; index < 100; index++) {
        found.test();
    }
    service2.stopRmiServer();
    try {
        found.test();
        Assert.fail("Expected service lookup to fail");
    } catch (FatalCoordinatorException ignore) {
        Assert.assertEquals(ServiceCode.COORDINATOR_ERROR, ignore.getServiceCode());
    }
    service2.startRmiServer();
    found.test();
}
Also used : FatalCoordinatorException(com.emc.storageos.coordinator.exceptions.FatalCoordinatorException) Service(com.emc.storageos.coordinator.common.Service) Test(org.junit.Test)

Aggregations

Service (com.emc.storageos.coordinator.common.Service)38 CoordinatorException (com.emc.storageos.coordinator.exceptions.CoordinatorException)13 ArrayList (java.util.ArrayList)12 IOException (java.io.IOException)11 ExecutorService (java.util.concurrent.ExecutorService)10 URI (java.net.URI)9 RetryableCoordinatorException (com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException)7 PropertyInfoMapper.decodeFromString (com.emc.storageos.coordinator.mapper.PropertyInfoMapper.decodeFromString)7 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)7 CoordinatorClientException (com.emc.storageos.systemservices.exceptions.CoordinatorClientException)6 InvalidLockOwnerException (com.emc.storageos.systemservices.exceptions.InvalidLockOwnerException)6 SyssvcException (com.emc.storageos.systemservices.exceptions.SyssvcException)6 RepositoryInfo (com.emc.storageos.coordinator.client.model.RepositoryInfo)4 CoordinatorClient (com.emc.storageos.coordinator.client.service.CoordinatorClient)4 UnknownHostException (java.net.UnknownHostException)4 HashMap (java.util.HashMap)4 Site (com.emc.storageos.coordinator.client.model.Site)3 SysClientException (com.emc.storageos.systemservices.exceptions.SysClientException)3 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3