public static String getIpAddress() { try { String hostname = getHostName(); return InetAddress.getByName(hostname).getHostAddress(); } catch (UnknownHostException uhe) { throw new IllegalStateException(uhe); } }
protected boolean sendUnregistrationEvent(KeycloakDeployment deployment) { log.debug("Sending Unregistration event right now"); String host = HostUtils.getHostName(); try { ServerRequest.invokeUnregisterNode(deployment, host); log.debugf("Node '%s' successfully unregistered from Keycloak", host); return true; } catch (ServerRequest.HttpFailure failure) { log.error("failed to unregister node from keycloak"); log.error("status from server: " + failure.getStatus()); if (failure.getError() != null) { log.error(" " + failure.getError()); } return false; } catch (IOException e) { log.error("failed to unregister node from keycloak", e); return false; } }
if (sessionId != null) { formparams.add(new BasicNameValuePair(AdapterConstants.CLIENT_SESSION_STATE, sessionId)); formparams.add(new BasicNameValuePair(AdapterConstants.CLIENT_SESSION_HOST, HostUtils.getHostName()));
if (sessionId != null) { formparams.add(new BasicNameValuePair(AdapterConstants.CLIENT_SESSION_STATE, sessionId)); formparams.add(new BasicNameValuePair(AdapterConstants.CLIENT_SESSION_HOST, HostUtils.getHostName()));
protected void sendRegistrationEvent(KeycloakDeployment deployment) { // This method is invoked from single-thread executor, so no synchronization is needed // However, it could happen that the same deployment was submitted more than once to that executor // Hence we need to recheck that the registration is really needed final String registrationUri = deployment.getRegisterNodeUrl(); if (! needRefreshRegistration(registrationUri, deployment)) { return; } if (Thread.currentThread().isInterrupted()) { return; } log.debug("Sending registration event right now"); String host = HostUtils.getHostName(); try { ServerRequest.invokeRegisterNode(deployment, host); NodeRegistrationContext regContext = new NodeRegistrationContext(Time.currentTime(), deployment); nodeRegistrations.put(deployment.getRegisterNodeUrl(), regContext); log.debugf("Node '%s' successfully registered in Keycloak", host); } catch (ServerRequest.HttpFailure failure) { log.error("failed to register node to keycloak"); log.error("status from server: " + failure.getStatus()); if (failure.getError() != null) { log.error(" " + failure.getError()); } } catch (IOException e) { log.error("failed to register node to keycloak", e); } }
private boolean acquireLock() { DBObject query = new BasicDBObject("locked", false); BasicDBObject update = new BasicDBObject("locked", true); update.append("_id", 1); update.append("lockedSince", Time.toMillis(Time.currentTime())); update.append("lockedBy", HostUtils.getHostName()); // Maybe replace with something better, but doesn't matter for now try { WriteResult wr = db.getCollection(DB_LOCK_COLLECTION).update(query, update, true, false); if (wr.getN() == 1) { logger.debugf("Successfully acquired DB lock"); factory.setHasLock(true); return true; } else { return false; } } catch (DuplicateKeyException dke) { logger.debugf("Failed acquire lock. Reason: %s", dke.getMessage()); } return false; }