public static NodeInformation createNodeInformation(String hostname, boolean ssl, boolean verifyCert, int port) { Map<String, String> serviceDetails = new HashMap<>(); serviceDetails.put("connectorType", "rest"); String protocol = "http"; if(ssl) { protocol = "https"; } serviceDetails.put("verifyCert", Boolean.toString(verifyCert)); serviceDetails.put("protocol", protocol); serviceDetails.put("host", hostname); serviceDetails.put("port", "" + port); serviceDetails.put("clientid", clientId); NodeInformation nodeInformation = new NodeInformation("", ""); nodeInformation.addServiceInformation(new ServiceInformation("rest", serviceDetails)); return nodeInformation; } }
public static String getServiceType(NodeInformation nodeInformation) { return getServiceType(nodeInformation.getGridId()); }
@Override public String getCachingKey(NodeInformation nodeInformation, Class<? extends RemoteConnector> operationInterface) { Map<String, String> props = nodeInformation.getServiceInformation("rest").getNodeProperties(); return nodeInformation.getInstanceId() + props.get(RemoteRestConnector.CONNECTION_HOST_PROPERTY) + props.get(RemoteRestConnector.CONNECTION_PORT_PROPERTY) + operationInterface.getName(); }
public static <T extends RemoteConnector> T createConnector(NodeInformation nodeInformation, Class<T> operationInterface) throws RemoteException { if(nodeInformation.getServiceInformationList().size() > 0) { String serviceType; if(nodeInformation.getServiceInformation(instance.preferredType) != null) { serviceType = instance.preferredType; } else { serviceType = nodeInformation.getServiceInformationList().get(0).getServiceType(); } Map<String, ?> properties = nodeInformation.getServiceInformation(serviceType).getNodeProperties(); if(serviceType != null && properties != null) { return instance.loadConnector(nodeInformation, serviceType, operationInterface); } } throw new RemoteException("Remote grid nodeInformation connection information contains not enough connection information: " + nodeInformation.toString()); }
public static Node mapTo(NodeInformation nodeInformation) { if(nodeInformation != null) { Node mappedNode = new Node(); mappedNode.setGridId(nodeInformation.getGridId()); mappedNode.setInstanceId(nodeInformation.getInstanceId()); List<NodeServiceInformation> nodeServices = new ArrayList<>(); for(ServiceInformation serviceInformation : nodeInformation.getServiceInformationList()) { NodeServiceInformation nodeService = new NodeServiceInformation(); nodeService.setProperties(serviceInformation.getNodeProperties()); nodeService.setServiceType(serviceInformation.getServiceType()); nodeServices.add(nodeService); } mappedNode.setServices(nodeServices); return mappedNode; } else { return null; } }
private void loadHostAddress(NodeInformation nodeInformation) throws ConfigurationException { Map<String, ?> remoteProperties = nodeInformation.getServiceInformation("rest").getNodeProperties(); if(remoteProperties.containsKey(CONNECTION_HOST_PROPERTY) && remoteProperties.containsKey(CONNECTION_PORT_PROPERTY) && remoteProperties.containsKey(CONNECTION_PROTOCOL_PROPERTY)) { String host = (String)remoteProperties.get(CONNECTION_HOST_PROPERTY); String port = (String)remoteProperties.get(CONNECTION_PORT_PROPERTY); String protocol = (String) remoteProperties.get(CONNECTION_PROTOCOL_PROPERTY); if(remoteProperties.containsKey("verifyCert") && remoteProperties.get("verifyCert").equals("false")) { disableCertificationValidation(); } if(protocol.equals("http") || protocol.equals("https")) { try { int portNumber = Integer.parseInt(port); this.baseUrl = protocol + "://" + host + ":" + portNumber + "/"; LOG.debug("Loaded rest connector with baseUrl: {}", baseUrl); } catch(NumberFormatException e) { throw new ConfigurationException("Invalid Rest client port number: " + port); } } else { throw new ConfigurationException("Unsupported Rest client protocol: " + protocol); } } else { throw new ConfigurationException("Unable to load remote connection properties to establish rest client connection"); } }
@Override public NodeInformation startEngine() throws JasDBException { LOG.info("Starting JasDB Database Engine"); engineVersion = loadVersionData(); GlobalCachingMemoryManager cachingMemoryManager = GlobalCachingMemoryManager.getGlobalInstance(); Configuration cachingConfiguration = configurationLoader.getConfiguration().getChildConfiguration("/jasdb/caching"); cachingMemoryManager.configure(cachingConfiguration); try { MBeanServer server = ManagementFactory.getPlatformMBeanServer(); ObjectName name = new ObjectName("nl.renarj.jasdb.core:type=KernelShutdown"); if(!server.isRegistered(name)) { server.registerMBean(new KernelShutdown(), name); } } catch (InstanceAlreadyExistsException | NotCompliantMBeanException | MalformedObjectNameException | MBeanRegistrationException e) { throw new ConfigurationException(UNABLE_TO_REGISTER_JMX_SHUTDOWN_HOOK, e); } remoteServiceManager.startRemoteServices(); this.nodeInformation = new NodeInformation(JasDBMetadataStore.PID, null); remoteServiceManager.getServiceInformation().forEach(r -> this.nodeInformation.addServiceInformation(r)); return nodeInformation; }