public static List<InetAddress> getAdresses() throws ConfigurationException { List<InetAddress> networkInetAdresses = new ArrayList<>(); try { Enumeration<NetworkInterface> networkInterfaceEnumerator = NetworkInterface.getNetworkInterfaces(); while(networkInterfaceEnumerator.hasMoreElements()) { NetworkInterface networkInterface = networkInterfaceEnumerator.nextElement(); Enumeration<InetAddress> addressEnumeration = networkInterface.getInetAddresses(); while(addressEnumeration.hasMoreElements()) { InetAddress address = addressEnumeration.nextElement(); if(!address.isLoopbackAddress() && !address.isLinkLocalAddress()) { networkInetAdresses.add(address); } } } } catch(SocketException e) { throw new ConfigurationException("Unable to get network interfaces to check for grid information", e); } return networkInetAdresses; }
public static InetAddress getPublicAddress() throws ConfigurationException { try { Enumeration<NetworkInterface> networkInterfaceEnumeration = NetworkInterface.getNetworkInterfaces(); while(networkInterfaceEnumeration.hasMoreElements()) { NetworkInterface networkInterface = networkInterfaceEnumeration.nextElement(); Enumeration<InetAddress> addressEnumeration = networkInterface.getInetAddresses(); while(addressEnumeration.hasMoreElements()) { InetAddress address = addressEnumeration.nextElement(); if(!address.isLinkLocalAddress() && !address.isLoopbackAddress()) { logger.debug("Found remote available network interface address: {}", address); return address; } } } } catch(SocketException e) { logger.error("Unable to load network interface information", e); } throw new ConfigurationException("Unable to get network interfaces to check for grid information"); }
private void loadNodeData() throws ConfigurationException { try { String address = GridLocatorUtil.getPublicAddress().getHostAddress(); Map<String, String> serviceProperties = new HashMap<>(); serviceProperties.put("connectorType", "console"); serviceProperties.put("protocol", "http"); serviceProperties.put("host", address); serviceProperties.put("port", "" + portNr); this.serviceInformation = new ServiceInformation("console", serviceProperties); } catch(ConfigurationException e) { throw new ConfigurationException("Unable to load public endpoint information", e); } }
private void loadNodeData() throws ConfigurationException { try { String address = GridLocatorUtil.getPublicAddress().getHostAddress(); Map<String, String> serviceProperties = new HashMap<>(); serviceProperties.put("connectorType", "rest"); serviceProperties.put("protocol", "http"); serviceProperties.put("host", address); serviceProperties.put("port", "" + portNr); this.serviceInformation = new ServiceInformation("rest", serviceProperties); } catch(ConfigurationException e) { throw new ConfigurationException("Unable to load public endpoint information", e); } }
@Override public DBInstance getInstance(String instanceId) throws ConfigurationException { if(StringUtils.stringEmpty(instanceId)) { return getInstance(); } else { if(instances.containsKey(instanceId)) { return instances.get(instanceId); } else { throw new ConfigurationException("No instance was found for id: " + instanceId); } } }
private void disableCertificationValidation() throws ConfigurationException { TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { @Override public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { } @Override public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { } @Override public X509Certificate[] getAcceptedIssuers() { return null; } } }; try { SSLContext sc = SSLContext.getInstance("SSL"); sc.init(null, trustAllCerts, new SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); } catch(NoSuchAlgorithmException | KeyManagementException e) { throw new ConfigurationException("Unable to disable SSL verification", e); } HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() { @Override public boolean verify(String s, SSLSession sslSession) { return true; } }); }
@Override public void openService(Configuration configuration) throws JasDBStorageException { LOG.info("Opening storage service for bag: {}", bagName); if(!recordWriterFactoryLoader.loadRecordWriter(instanceId, bagName).isOpen()) { throw new ConfigurationException("Unable to open record writer for instance/bag: " + instanceId + '/' + bagName); } if(!metadataStore.isLastShutdownClean() || Boolean.parseBoolean(System.getProperty(FORCE_REBUILD_COMMAND))) { LOG.info("Previous shutdown of: {} was unclean or forced rebuild triggered, scanning and rebuilding indexes", this); handleIndexScanAndRebuild(); } LOG.info("Finished opening storage service for bag: {}", bagName); }
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"); } }
@Autowired public RecordWriterFactoryLoader(ConfigurationLoader configurationLoader, MetadataStore metadataStore) throws ConfigurationException { Configuration configuration = configurationLoader.getConfiguration(); Configuration recordWriterConfiguration = configuration.getChildConfiguration("/jasdb/Storage/RecordWriter"); String recordWriterProvider = recordWriterConfiguration != null ? recordWriterConfiguration.getAttribute("provider", DEFAULT_PROVIDER) : DEFAULT_PROVIDER; ServiceLoader<RecordWriterFactory> recordWriterFactories = ServiceLoader.load(RecordWriterFactory.class); for(RecordWriterFactory recordWriterFactory : recordWriterFactories) { if(recordWriterFactory.providerName().equals(recordWriterProvider)) { this.recordWriterFactory = (RecordWriterFactory<UUIDKey>)recordWriterFactory; LOG.info("Using RecordWriterFactory: {}", recordWriterFactory); } } if(recordWriterFactory == null) { throw new ConfigurationException("No record writer factory is available, could not load configured provider: " + recordWriterProvider); } this.metadataStore = metadataStore; }
public JasDBConfigurationLoader() throws ConfigurationException { try { String overrideConfigProperty = System.getProperty("jasdb-config"); if(StringUtils.stringEmpty(overrideConfigProperty)) { this.configuration = XMLConfiguration.loadConfiguration(JASDB_CONFIG); } else { LOG.info("Override configuration path specified: {}", overrideConfigProperty); this.configuration = XMLConfiguration.loadConfiguration(overrideConfigProperty); } } catch (CoreConfigException e) { try { this.configuration = XMLConfiguration.loadConfiguration(FALLBACK_JASDB_XML); } catch(CoreConfigException ex) { throw new ConfigurationException("Unable to load Default JasDB configuration file", ex); } } }
@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; }
public void configure(Configuration configuration) throws ConfigurationException { String maxMemoryValue = null; String monitorIntervalValue = DEFAULT_MONITOR_INTERVAL; if(configuration != null) { maxMemoryValue = configuration.getAttribute("MaxMemory"); monitorIntervalValue = configuration.getAttribute("MemoryMonitorInterval", DEFAULT_MONITOR_INTERVAL); } long monitorInterval; try { monitorInterval = ValueConverterUtil.convertToMilliseconds(monitorIntervalValue); if(StringUtils.stringNotEmpty(maxMemoryValue)) { maximumMemory = ValueConverterUtil.convertToBytes(maxMemoryValue); } else { maximumMemory = Runtime.getRuntime().maxMemory(); } } catch(CoreConfigException e) { throw new ConfigurationException("Unable to load caching settings", e); } LOG.info("Global cache monitor starting with interval: {} and memory limit: {} bytes", monitorInterval, maximumMemory); this.cacheMonitorThread = new CacheMonitorThread(this, monitorInterval, maximumMemory); this.cacheMonitorThread.start(); }