Search in sources :

Example 71 with UnknownHostException

use of java.net.UnknownHostException in project OpenAM by OpenRock.

the class TestPacket method testSerializingRfc2865Section7dot1Example.

/**
     * Test to ensure conformity with <a href="https://tools.ietf.org/html/rfc2865#section-7.1">IETF RFC 2865 section
     * 7.1</a>
     */
@Test
public void testSerializingRfc2865Section7dot1Example() {
    // what we should end up with
    final String res = "01 00 00 38 0f 40 3f 94 73 97 80 57 bd 83 d5 cb " + "98 f4 22 7a 01 06 6e 65 6d 6f 02 12 0d be 70 8d " + "93 d4 13 ce 31 96 e4 3f 78 2a 0a ee 04 06 c0 a8 " + "01 10 05 06 00 00 00 03";
    final AccessRequest accessReq = new AccessRequest();
    accessReq.setIdentifier((short) 0);
    accessReq.addAttribute(new UserNameAttribute("nemo"));
    final String authenticatorBytes = "0f 40 3f 94 73 97 80 57 bd 83 d5 cb 98 f4 22 7a";
    final byte[] aBytes = Utils.toByteArray(authenticatorBytes);
    final RequestAuthenticator authenticator = new RequestAuthenticator(aBytes);
    accessReq.setAuthenticator(authenticator);
    accessReq.addAttribute(new UserPasswordAttribute(authenticator, Rfc2865Examples.secret, Rfc2865Examples.password));
    try {
        final InetAddress address = InetAddress.getByAddress(new byte[] { (byte) 192, (byte) 168, 1, 16 });
        accessReq.addAttribute(new NASIPAddressAttribute(address));
    } catch (final UnknownHostException e) {
        // ignore since it won't happen given valid address
        e.printStackTrace();
    }
    accessReq.addAttribute(new NASPortAttribute(3));
    final byte[] bytes = accessReq.getOctets();
    final ByteBuffer pktBfr = ByteBuffer.wrap(bytes);
    final String spaceHex = Utils.toSpacedHex(pktBfr);
    Assert.assertEquals(spaceHex, res, "output sequence of AccessRequest should have matched");
}
Also used : UnknownHostException(java.net.UnknownHostException) NASPortAttribute(org.forgerock.openam.radius.common.packet.NASPortAttribute) NASIPAddressAttribute(org.forgerock.openam.radius.common.packet.NASIPAddressAttribute) InetAddress(java.net.InetAddress) ByteBuffer(java.nio.ByteBuffer) Test(org.testng.annotations.Test)

Example 72 with UnknownHostException

use of java.net.UnknownHostException in project OpenAM by OpenRock.

the class FSAssertionManager method createFSAssertion.

/**
     * Creates an assertion artifact.
     * @param id session ID
     * @param artifact assertion artifact
     * @param realm the realm under which the entity resides.
     * @param spEntityID service provider's entity ID
     * @param spHandle service provider issued <code>NameIdentifier</code>
     * @param idpHandle identity provider issued <code>NameIdentifier</code>
     * @param inResponseTo value to InResponseTo attribute. It's the request ID.
     * @param assertionMinorVersion minor version the assertion should use
     * @exception FSException,SAMLException if error occurrs
     */
public FSAssertion createFSAssertion(String id, AssertionArtifact artifact, String realm, String spEntityID, NameIdentifier spHandle, NameIdentifier idpHandle, String inResponseTo, int assertionMinorVersion) throws FSException, SAMLException {
    FSUtils.debug.message("FSAssertionManager.createFSAssertion(id): Called");
    // check input
    if ((id == null) || (spEntityID == null)) {
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("FSAssertionManager: null input for" + " method createFSAssertion.");
        }
        throw new FSException("nullInput", null);
    }
    String destID = spEntityID;
    String authMethod = null;
    String authnContextStatementRef = null;
    String authnContextClassRef = null;
    Date authInstant = null;
    String securityDomain = null;
    Object token = null;
    String univId = null;
    SubjectLocality authLocality = null;
    FSSessionManager sessionManager = FSSessionManager.getInstance(metaAlias);
    IDFFMetaManager metaManager = FSUtils.getIDFFMetaManager();
    Map attributes = new HashMap();
    if (metaManager != null) {
        BaseConfigType idpConfig = null;
        try {
            idpConfig = metaManager.getIDPDescriptorConfig(realm, hostEntityId);
        } catch (IDFFMetaException e) {
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("FSAssertionManager.createFSAssertion: exception while" + " obtaining idp extended meta:", e);
            }
            idpConfig = null;
        }
        if (idpConfig != null) {
            attributes = IDFFMetaUtils.getAttributes(idpConfig);
        }
    }
    try {
        SessionProvider sessionProvider = SessionManager.getProvider();
        token = sessionProvider.getSession(id);
        String[] strAuthInst = null;
        try {
            strAuthInst = sessionProvider.getProperty(token, SessionProvider.AUTH_INSTANT);
        } catch (UnsupportedOperationException ue) {
            if (FSUtils.debug.warningEnabled()) {
                FSUtils.debug.warning("FSAssertionManager.createFSAssertion(id):", ue);
            }
        } catch (SessionException se) {
            if (FSUtils.debug.warningEnabled()) {
                FSUtils.debug.warning("FSAssertionManager.createFSAssertion(id):", se);
            }
        }
        if ((strAuthInst != null) && (strAuthInst.length >= 1)) {
            try {
                authInstant = DateUtils.stringToDate(strAuthInst[0]);
            } catch (ParseException ex) {
                if (FSUtils.debug.messageEnabled()) {
                    FSUtils.debug.message("FSAssertionManager." + "createFSAssertion(id): AuthInstant not found" + "in the Token");
                }
            }
        } else {
            authInstant = new java.util.Date();
        }
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("FSAssertionManager.createFSAssertion(id):AuthInstant = " + authInstant);
        }
        try {
            String[] strAuthMethod = sessionProvider.getProperty(token, SessionProvider.AUTH_METHOD);
            if ((strAuthMethod != null) && (strAuthMethod.length >= 1)) {
                authMethod = strAuthMethod[0];
            }
        } catch (UnsupportedOperationException ue) {
            if (FSUtils.debug.warningEnabled()) {
                FSUtils.debug.warning("FSAssertionManager.createFSAssertion(id):", ue);
            }
        } catch (SessionException se) {
            if (FSUtils.debug.warningEnabled()) {
                FSUtils.debug.warning("FSAssertionManager.createFSAssertion(id):", se);
            }
        }
        String assertionIssuer = IDFFMetaUtils.getFirstAttributeValue(attributes, IFSConstants.ASSERTION_ISSUER);
        if (assertionIssuer == null) {
            assertionIssuer = SystemConfigurationUtil.getProperty("com.iplanet.am.server.host");
        }
        try {
            String ipAddress = InetAddress.getByName(assertionIssuer).getHostAddress();
            authLocality = new SubjectLocality(ipAddress, assertionIssuer);
        } catch (UnknownHostException uhe) {
            FSUtils.debug.error("FSAssertionManager.constructor: couldn't" + " obtain the localhost's ipaddress:", uhe);
        }
        try {
            FSSession session = sessionManager.getSession(token);
            authnContextClassRef = session.getAuthnContext();
            authnContextStatementRef = authnContextClassRef;
        } catch (Exception ex) {
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("FSAssertionManager.createFSAssertion" + "(id): AuthnContextStatement for the token is null" + " Assertion will not contain any " + " AuthenticationStatement");
            }
            authnContextStatementRef = null;
        }
        if (authnContextStatementRef != null) {
            if (assertionMinorVersion == IFSConstants.FF_11_ASSERTION_MINOR_VERSION) {
                authMethod = IFSConstants.AC_XML_NS;
            } else {
                authMethod = IFSConstants.AC_12_XML_NS;
            }
        }
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("FSAssertionManager.createFSAssertion(id):" + "AuthnContextStatement used for authenticating the user: " + authnContextStatementRef);
        }
        univId = sessionProvider.getPrincipalName(token);
        securityDomain = hostEntityId;
    } catch (Exception e) {
        FSUtils.debug.error("FSAssertionManager.createAssertion(id):" + " exception retrieving info from the session: ", e);
        throw new FSException("alliance_manager_no_local_descriptor", null, e);
    }
    if (FSUtils.debug.messageEnabled()) {
        FSUtils.debug.message("FSAssertionManager.createAssertion(id):" + " Creating Authentication Assertion for user with" + "opaqueHandle= " + spHandle.getName() + " And SecurityDomain= " + securityDomain);
    }
    SubjectConfirmation subConfirmation = null;
    String artString = null;
    if (artifact != null) {
        artString = artifact.getAssertionArtifact();
        if (assertionMinorVersion == IFSConstants.FF_11_ASSERTION_MINOR_VERSION) {
            subConfirmation = new SubjectConfirmation(SAMLConstants.DEPRECATED_CONFIRMATION_METHOD_ARTIFACT);
        } else {
            subConfirmation = new SubjectConfirmation(SAMLConstants.CONFIRMATION_METHOD_ARTIFACT);
        }
        subConfirmation.setSubjectConfirmationData(artString);
    } else {
        // set to bearer for POST profile
        subConfirmation = new SubjectConfirmation(SAMLConstants.CONFIRMATION_METHOD_BEARER);
    }
    IDPProvidedNameIdentifier idpNi = null;
    if (assertionMinorVersion == IFSConstants.FF_12_POST_ASSERTION_MINOR_VERSION || assertionMinorVersion == IFSConstants.FF_12_ART_ASSERTION_MINOR_VERSION) {
        idpNi = new IDPProvidedNameIdentifier(idpHandle.getName(), idpHandle.getNameQualifier(), spHandle.getFormat());
        idpNi.setMinorVersion(IFSConstants.FF_12_PROTOCOL_MINOR_VERSION);
    } else {
        idpNi = new IDPProvidedNameIdentifier(idpHandle.getNameQualifier(), idpHandle.getName());
    }
    FSSubject sub = new FSSubject(spHandle, subConfirmation, idpNi);
    AuthnContext authnContext = new AuthnContext(authnContextClassRef, authnContextStatementRef);
    authnContext.setMinorVersion(assertionMinorVersion);
    FSAuthenticationStatement statement = new FSAuthenticationStatement(authMethod, authInstant, sub, authLocality, null, authnContext);
    FSSession session = sessionManager.getSession(univId, id);
    if (session == null) {
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("FSAssertionManager.createAssertion(id): " + "AssertionManager could not find a valid Session for" + "userId: " + univId + " SessionID: " + id);
        }
        return null;
    }
    String sessionIndex = session.getSessionIndex();
    if (sessionIndex == null) {
        sessionIndex = SAMLUtils.generateID();
        session.setSessionIndex(sessionIndex);
    }
    if (FSUtils.debug.messageEnabled()) {
        FSUtils.debug.message("FSAssertionManager.createAssertion(id): SessionIndex: " + sessionIndex);
    }
    statement.setSessionIndex(sessionIndex);
    //setReauthenticateOnOrAfter date
    Date issueInstant = new Date();
    // get this period from the config
    FSUtils.debug.message("here before date");
    Date notAfter;
    if (artifact != null) {
        notAfter = new Date(issueInstant.getTime() + artifactTimeout);
    } else {
        notAfter = new Date(issueInstant.getTime() + assertionTimeout);
    }
    FSUtils.debug.message("here after date");
    statement.setReauthenticateOnOrAfter(notAfter);
    if (FSUtils.debug.messageEnabled()) {
        FSUtils.debug.message("FSAssertionManager.createAssertion(id):" + " Authentication Statement: " + statement.toXMLString());
    }
    Conditions cond = new Conditions(null, notAfter);
    if ((destID != null) && (destID.length() != 0)) {
        List targets = new ArrayList();
        targets.add(destID);
        cond.addAudienceRestrictionCondition(new AudienceRestrictionCondition(targets));
    }
    if (FSUtils.debug.messageEnabled()) {
        FSUtils.debug.message("FSAssertionManager.createAssertion(id):" + " Authentication Statement: " + statement.toXMLString());
    }
    /**
         * This is added to create an attribute statement for the bootstrap
         * information.
         */
    AttributeStatement attribStatement = null;
    Advice advice = null;
    String generateBootstrapping = IDFFMetaUtils.getFirstAttributeValue(attributes, IFSConstants.GENERATE_BOOTSTRAPPING);
    if (assertionMinorVersion != IFSConstants.FF_11_ASSERTION_MINOR_VERSION && (generateBootstrapping != null && generateBootstrapping.equals("true"))) {
        AuthnContext authContext = new AuthnContext(null, authnContextStatementRef);
        authContext.setMinorVersion(IFSConstants.FF_12_PROTOCOL_MINOR_VERSION);
        try {
            FSDiscoveryBootStrap bootStrap = new FSDiscoveryBootStrap(token, authContext, sub, univId, destID, realm);
            attribStatement = bootStrap.getBootStrapStatement();
            if (bootStrap.hasCredentials()) {
                advice = bootStrap.getCredentials();
            }
        } catch (Exception e) {
            FSUtils.debug.error("FSAssertionManager.createAssertion(id):" + "exception when generating bootstrapping resource " + "offering:", e);
        }
    }
    AssertionIDReference aID = new AssertionIDReference();
    Set statements = new HashSet();
    statements.add(statement);
    if (attribStatement != null) {
        statements.add(attribStatement);
    }
    String attributePluginImpl = IDFFMetaUtils.getFirstAttributeValue(attributes, IFSConstants.ATTRIBUTE_PLUGIN);
    if ((attributePluginImpl != null) && (attributePluginImpl.length() != 0)) {
        try {
            Object pluginClass = Thread.currentThread().getContextClassLoader().loadClass(attributePluginImpl).newInstance();
            List attribStatements = null;
            if (pluginClass instanceof FSRealmAttributePlugin) {
                FSRealmAttributePlugin attributePlugin = (FSRealmAttributePlugin) pluginClass;
                attribStatements = attributePlugin.getAttributeStatements(realm, hostEntityId, destID, sub, token);
            } else if (pluginClass instanceof FSAttributePlugin) {
                FSAttributePlugin attributePlugin = (FSAttributePlugin) pluginClass;
                attribStatements = attributePlugin.getAttributeStatements(hostEntityId, destID, sub, token);
            }
            if ((attribStatements != null) && (attribStatements.size() != 0)) {
                Iterator iter = attribStatements.iterator();
                while (iter.hasNext()) {
                    statements.add((AttributeStatement) iter.next());
                }
            }
        } catch (Exception ex) {
            FSUtils.debug.error("FSAssertion.createAssertion(id):getAttributePlugin:", ex);
        }
    }
    if (IDFFMetaUtils.isAutoFedEnabled(attributes)) {
        AttributeStatement autoFedStatement = FSAttributeStatementHelper.getAutoFedAttributeStatement(realm, hostEntityId, sub, token);
        statements.add(autoFedStatement);
    }
    FSAssertion assertion = new FSAssertion(aID.getAssertionIDReference(), hostEntityId, issueInstant, cond, advice, statements, inResponseTo);
    assertion.setMinorVersion(assertionMinorVersion);
    assertion.setID(aID.getAssertionIDReference());
    if (FSUtils.debug.messageEnabled()) {
        FSUtils.debug.message("FSAssertionManager.createAssertion(id):" + " Assertion created successfully: " + assertion.toXMLString());
    }
    String aIDString = assertion.getAssertionID();
    Entry entry = new Entry(assertion, destID, artString, token);
    Integer maxNumber = null;
    try {
        int temp = Integer.parseInt(IDFFMetaUtils.getFirstAttributeValue(attributes, IFSConstants.ASSERTION_LIMIT));
        maxNumber = new Integer(temp);
    } catch (Exception ex) {
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("FSAssertionManager.createAssertion(id):" + " Assertion MAX number configuration not found in " + "FSConfig. Using Default");
        }
        maxNumber = null;
    }
    if (maxNumber == null) {
        maxNumber = new Integer(IFSConstants.ASSERTION_MAX_NUMBER_DEFAULT);
    }
    int maxValue = maxNumber.intValue();
    if ((maxValue != 0) && (idEntryMap.size() > maxValue)) {
        FSUtils.debug.error("FSAssertionManager.createAssertion: " + "reached maxNumber of assertions.");
        throw new FSException("errorCreateAssertion", null);
    }
    Object oldEntry = null;
    try {
        synchronized (idEntryMap) {
            oldEntry = idEntryMap.put(aIDString, entry);
        }
        if ((agent != null) && agent.isRunning() && (idffSvc != null)) {
            idffSvc.setAssertions((long) idEntryMap.size());
        }
    } catch (Exception e) {
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("FSAssertionManager: couldn't add " + "to idEntryMap.", e);
        }
        throw new FSException("errorCreateAssertion", null);
    }
    if (LogUtil.isAccessLoggable(Level.FINER)) {
        String[] data = { assertion.toString() };
        LogUtil.access(Level.FINER, LogUtil.CREATE_ASSERTION, data, token);
    } else {
        String[] data = { assertion.getAssertionID() };
        LogUtil.access(Level.INFO, LogUtil.CREATE_ASSERTION, data, token);
    }
    if (artString != null) {
        try {
            synchronized (artIdMap) {
                oldEntry = artIdMap.put(artString, aIDString);
            }
            if ((agent != null) && agent.isRunning() && (idffSvc != null)) {
                idffSvc.setArtifacts((long) artIdMap.size());
            }
        } catch (Exception e) {
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("FSAssertionManager: couldn't add " + "artifact to the artIdMap.", e);
            }
            throw new FSException("errorCreateArtifact", null);
        }
        if (oldEntry != null) {
            artifactTimeoutRunnable.removeElement(aIDString);
        }
        artifactTimeoutRunnable.addElement(aIDString);
    } else {
        if (oldEntry != null) {
            assertionTimeoutRunnable.removeElement(aIDString);
        }
        assertionTimeoutRunnable.addElement(aIDString);
    }
    if (FSUtils.debug.messageEnabled()) {
        FSUtils.debug.message("FSAssertionManager.createAssertion(id):" + " Returning Assertion: " + assertion.toXMLString());
    }
    return assertion;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) FSSubject(com.sun.identity.federation.message.FSSubject) Date(java.util.Date) ArrayList(java.util.ArrayList) SessionException(com.sun.identity.plugin.session.SessionException) SubjectLocality(com.sun.identity.saml.assertion.SubjectLocality) Conditions(com.sun.identity.saml.assertion.Conditions) AuthnContext(com.sun.identity.federation.message.common.AuthnContext) BaseConfigType(com.sun.identity.federation.jaxb.entityconfig.BaseConfigType) SubjectConfirmation(com.sun.identity.saml.assertion.SubjectConfirmation) FSAssertion(com.sun.identity.federation.message.FSAssertion) FSException(com.sun.identity.federation.common.FSException) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) AudienceRestrictionCondition(com.sun.identity.saml.assertion.AudienceRestrictionCondition) SessionProvider(com.sun.identity.plugin.session.SessionProvider) HashSet(java.util.HashSet) UnknownHostException(java.net.UnknownHostException) FSAuthenticationStatement(com.sun.identity.federation.message.FSAuthenticationStatement) IDFFMetaException(com.sun.identity.federation.meta.IDFFMetaException) Date(java.util.Date) SessionException(com.sun.identity.plugin.session.SessionException) IDFFMetaException(com.sun.identity.federation.meta.IDFFMetaException) ParseException(java.text.ParseException) SAMLException(com.sun.identity.saml.common.SAMLException) FSException(com.sun.identity.federation.common.FSException) UnknownHostException(java.net.UnknownHostException) IDFFMetaManager(com.sun.identity.federation.meta.IDFFMetaManager) AttributeStatement(com.sun.identity.saml.assertion.AttributeStatement) ParseException(java.text.ParseException) Advice(com.sun.identity.saml.assertion.Advice) IDPProvidedNameIdentifier(com.sun.identity.federation.message.common.IDPProvidedNameIdentifier) AssertionIDReference(com.sun.identity.saml.assertion.AssertionIDReference) Map(java.util.Map) HashMap(java.util.HashMap)

Example 73 with UnknownHostException

use of java.net.UnknownHostException in project OpenAM by OpenRock.

the class InternalSession method internalPutProperty.

/**
     * Sets the key-value pair in the Internal Session property table.
     *
     * @param key
     *            Property key
     * @param value
     *            Property value for the key
     */
protected void internalPutProperty(String key, String value) {
    if (key.equals(HOST_NAME) || key.equals(HOST)) {
        if (value == null || value.length() == 0) {
            return;
        }
        if (isEnableHostLookUp) {
            try {
                InetAddress address = java.net.InetAddress.getByName(value);
                String hostName = address.getHostName();
                sessionProperties.put(HOST_NAME, hostName);
                sessionProperties.put(HOST, value);
            } catch (UnknownHostException uhe) {
                debug.error("InternalSession.internalputProperty():" + "Unable to get HostName for:" + value + " SessionException: ", uhe);
            }
        } else {
            sessionProperties.put(HOST_NAME, value);
            sessionProperties.put(HOST, value);
        }
    } else if (key.equals(AM_MAX_IDLE_TIME)) {
        setMaxIdleTime(Long.parseLong(value));
    } else if (key.equals(AM_MAX_SESSION_TIME)) {
        setMaxSessionTime(Long.parseLong(value));
    } else {
        sessionProperties.put(key, value);
    }
    if (sessionState == VALID && serviceConfig.isSendPropertyNotification(key)) {
        sessionService.sendEvent(this, SessionEvent.PROPERTY_CHANGED);
        SessionInfo sessionInfo = toSessionInfo();
        sessionLogging.logEvent(sessionInfo, SessionEvent.PROPERTY_CHANGED);
        sessionAuditor.auditActivity(sessionInfo, AM_SESSION_PROPERTY_CHANGED);
    }
    updateForFailover();
}
Also used : UnknownHostException(java.net.UnknownHostException) SessionInfo(com.iplanet.dpro.session.share.SessionInfo) InetAddress(java.net.InetAddress)

Example 74 with UnknownHostException

use of java.net.UnknownHostException in project SmartCity-Market by TechnionYP5777.

the class Main method main.

public static void main(String[] args) {
    if (!parseArguments(args))
        return;
    /* Setting log properties */
    PropertyConfigurator.configure("../log4j.properties");
    log.setLevel(verbosity);
    CommandProcess commandProcess = new CommandProcess();
    ThreadPooledServer server = null;
    try {
        server = new ThreadPooledServer(port, numOfThreads, commandProcess, serverIP);
    } catch (UnknownHostException e1) {
        log.fatal("Server IP address leads to unknown host, server won't start.");
        return;
    }
    SQLDatabaseConnection connection = new SQLDatabaseConnection();
    log.info("Disconnect from all clients");
    try {
        connection.logoutAllUsers();
        connection.close();
    } catch (CriticalError e1) {
        log.fatal("Disconnect failed");
        return;
    }
    log.info("Starting Server.");
    new Thread(server).start();
    try {
        Thread.sleep(1000 * timeout);
    } catch (InterruptedException e) {
        /* Get interrupt to stop server */
        log.info("Server Got interrupted.");
    }
    log.info("Stopping server.");
    server.stop();
}
Also used : CommandProcess(CommandHandler.CommandProcess) SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) UnknownHostException(java.net.UnknownHostException) ThreadPooledServer(ClientServerCommunication.ThreadPooledServer)

Example 75 with UnknownHostException

use of java.net.UnknownHostException in project voltdb by VoltDB.

the class SystemInformation method populateOverviewTable.

/**
     * Accumulate per-host information and return as a table.
     * This function does the real work. Everything else is
     * boilerplate sysproc stuff.
     */
public static VoltTable populateOverviewTable() {
    VoltTable vt = constructOverviewTable();
    int hostId = VoltDB.instance().getHostMessenger().getHostId();
    // try to get the external interface first, if none was set, use local addresses
    InetAddress addr = null;
    String clientInterface = null;
    int clientPort = VoltDB.DEFAULT_PORT;
    String adminInterface = null;
    int adminPort = VoltDB.DEFAULT_ADMIN_PORT;
    String httpInterface = null;
    int httpPort = VoltDB.DEFAULT_HTTP_PORT;
    String internalInterface = null;
    int internalPort = Constants.DEFAULT_INTERNAL_PORT;
    String zkInterface = null;
    int zkPort = Constants.DEFAULT_ZK_PORT;
    String drInterface = null;
    int drPort = VoltDB.DEFAULT_DR_PORT;
    String publicInterface = null;
    try {
        String localMetadata = VoltDB.instance().getLocalMetadata();
        JSONObject jsObj = new JSONObject(localMetadata);
        JSONArray interfaces = jsObj.getJSONArray("interfaces");
        String iface = interfaces.getString(0);
        addr = InetAddress.getByName(iface);
        clientPort = jsObj.getInt("clientPort");
        clientInterface = jsObj.getString("clientInterface");
        adminPort = jsObj.getInt("adminPort");
        adminInterface = jsObj.getString("adminInterface");
        httpPort = jsObj.getInt("httpPort");
        httpInterface = jsObj.getString("httpInterface");
        internalPort = jsObj.getInt("internalPort");
        internalInterface = jsObj.getString("internalInterface");
        zkPort = jsObj.getInt("zkPort");
        zkInterface = jsObj.getString("zkInterface");
        drPort = jsObj.getInt("drPort");
        drInterface = jsObj.getString("drInterface");
        publicInterface = jsObj.getString("publicInterface");
    } catch (JSONException e) {
        hostLog.info("Failed to get local metadata, falling back to first resolvable IP address.");
    } catch (UnknownHostException e) {
        hostLog.info("Failed to determine hostname, falling back to first resolvable IP address.");
    }
    // host name and IP address.
    if (addr == null) {
        addr = org.voltcore.utils.CoreUtils.getLocalAddress();
    }
    vt.addRow(hostId, "IPADDRESS", addr.getHostAddress());
    vt.addRow(hostId, "HOSTNAME", CoreUtils.getHostnameOrAddress());
    vt.addRow(hostId, "CLIENTINTERFACE", clientInterface);
    vt.addRow(hostId, "CLIENTPORT", Integer.toString(clientPort));
    vt.addRow(hostId, "ADMININTERFACE", adminInterface);
    vt.addRow(hostId, "ADMINPORT", Integer.toString(adminPort));
    vt.addRow(hostId, "HTTPINTERFACE", httpInterface);
    vt.addRow(hostId, "HTTPPORT", Integer.toString(httpPort));
    vt.addRow(hostId, "INTERNALINTERFACE", internalInterface);
    vt.addRow(hostId, "INTERNALPORT", Integer.toString(internalPort));
    vt.addRow(hostId, "ZKINTERFACE", zkInterface);
    vt.addRow(hostId, "ZKPORT", Integer.toString(zkPort));
    vt.addRow(hostId, "DRINTERFACE", drInterface);
    vt.addRow(hostId, "DRPORT", Integer.toString(drPort));
    vt.addRow(hostId, "PUBLICINTERFACE", publicInterface);
    // build string
    vt.addRow(hostId, "BUILDSTRING", VoltDB.instance().getBuildString());
    // version
    vt.addRow(hostId, "VERSION", VoltDB.instance().getVersionString());
    // catalog path
    String path = VoltDB.instance().getConfig().m_pathToCatalog;
    if (path != null && !path.startsWith("http"))
        path = (new File(path)).getAbsolutePath();
    vt.addRow(hostId, "CATALOG", path);
    // deployment path
    path = VoltDB.instance().getConfig().m_pathToDeployment;
    if (path != null && !path.startsWith("http"))
        path = (new File(path)).getAbsolutePath();
    vt.addRow(hostId, "DEPLOYMENT", path);
    String cluster_state = VoltDB.instance().getMode().toString();
    vt.addRow(hostId, "CLUSTERSTATE", cluster_state);
    // INITIALIZED, used by VEM to determine the spinny icon state.
    org.voltdb.OperationMode mode = VoltDB.instance().getMode();
    String areInitialized = Boolean.toString(!VoltDB.instance().rejoining() && (mode == org.voltdb.OperationMode.RUNNING || mode == org.voltdb.OperationMode.PAUSED));
    vt.addRow(hostId, "INITIALIZED", areInitialized);
    String replication_role = VoltDB.instance().getReplicationRole().toString();
    vt.addRow(hostId, "REPLICATIONROLE", replication_role);
    vt.addRow(hostId, "LASTCATALOGUPDATETXNID", Long.toString(VoltDB.instance().getCatalogContext().m_transactionId));
    vt.addRow(hostId, "CATALOGCRC", Long.toString(VoltDB.instance().getCatalogContext().getCatalogCRC()));
    vt.addRow(hostId, "IV2ENABLED", "true");
    long startTimeMs = VoltDB.instance().getHostMessenger().getInstanceId().getTimestamp();
    vt.addRow(hostId, "STARTTIME", Long.toString(startTimeMs));
    vt.addRow(hostId, "UPTIME", MiscUtils.formatUptime(VoltDB.instance().getClusterUptime()));
    SocketHubAppender hubAppender = (SocketHubAppender) Logger.getRootLogger().getAppender("hub");
    int port = 0;
    if (hubAppender != null)
        port = hubAppender.getPort();
    vt.addRow(hostId, "LOG4JPORT", Integer.toString(port));
    //Add license information
    if (MiscUtils.isPro()) {
        vt.addRow(hostId, "LICENSE", VoltDB.instance().getLicenseInformation());
    }
    populatePartitionGroups(hostId, vt);
    // root path
    vt.addRow(hostId, "VOLTDBROOT", VoltDB.instance().getVoltDBRootPath());
    vt.addRow(hostId, "FULLCLUSTERSIZE", Integer.toString(VoltDB.instance().getCatalogContext().getClusterSettings().hostcount()));
    vt.addRow(hostId, "CLUSTERID", Integer.toString(VoltDB.instance().getCatalogContext().getCluster().getDrclusterid()));
    return vt;
}
Also used : UnknownHostException(java.net.UnknownHostException) SocketHubAppender(org.apache.log4j.net.SocketHubAppender) JSONArray(org.json_voltpatches.JSONArray) JSONException(org.json_voltpatches.JSONException) VoltTable(org.voltdb.VoltTable) JSONObject(org.json_voltpatches.JSONObject) InetAddress(java.net.InetAddress) File(java.io.File)

Aggregations

UnknownHostException (java.net.UnknownHostException)1736 InetAddress (java.net.InetAddress)726 IOException (java.io.IOException)446 InetSocketAddress (java.net.InetSocketAddress)150 ArrayList (java.util.ArrayList)142 SocketException (java.net.SocketException)135 Test (org.junit.Test)122 Socket (java.net.Socket)93 URL (java.net.URL)77 SocketTimeoutException (java.net.SocketTimeoutException)71 HashMap (java.util.HashMap)71 File (java.io.File)67 MalformedURLException (java.net.MalformedURLException)65 NetworkInterface (java.net.NetworkInterface)58 URI (java.net.URI)55 ConnectException (java.net.ConnectException)54 InputStream (java.io.InputStream)53 Inet4Address (java.net.Inet4Address)52 Inet6Address (java.net.Inet6Address)52 List (java.util.List)51