Example usage for org.apache.commons.lang SystemUtils IS_OS_LINUX

List of usage examples for org.apache.commons.lang SystemUtils IS_OS_LINUX

Introduction

In this page you can find the example usage for org.apache.commons.lang SystemUtils IS_OS_LINUX.

Prototype

boolean IS_OS_LINUX

To view the source code for org.apache.commons.lang SystemUtils IS_OS_LINUX.

Click Source Link

Document

Is true if this is Linux.

The field will return false if OS_NAME is null.

Usage

From source file:configuration.Util.java

/**
 * Get the OS executable for docker//from   w w w .  j a  v a 2  s  .  co  m
 */

public static String getOSCommandLine(workflow_properties properties) {
    if (config.getBoolean("MacOSX") || SystemUtils.IS_OS_MAC_OSX) {
        return properties.getExecutableMacOSX();
    } else if (config.getBoolean("Linux") || SystemUtils.IS_OS_LINUX || SystemUtils.IS_OS_UNIX) {
        return properties.getExecutableLinux();
    }
    return properties.getExecutable();
}

From source file:com.vmware.identity.idm.client.TenantManagementTest.java

@TestOrderAnnotation(order = 25)
@Test//from   w ww.  java 2  s.  c o  m
public void testAddRemoveLocalOsFsptestUser() throws Exception, IDMException {
    if (SystemUtils.IS_OS_LINUX) {
        CasIdmClient idmClient = getIdmClient();

        String tenantName = idmClient.getDefaultTenant();
        Assert.assertNotNull(tenantName);

        Collection<IIdentityStoreData> stores = idmClient.getProviders(tenantName,
                EnumSet.of(DomainType.LOCAL_OS_DOMAIN));
        if (stores == null || stores.isEmpty()) {
            // add the localOs
            final String localOsDomainName = "localOsDomain";
            IIdentityStoreData localOsProvider = IdentityStoreData
                    .CreateLocalOSIdentityStoreData(localOsDomainName);
            idmClient.addProvider(tenantName, localOsProvider);

            stores = idmClient.getProviders(tenantName, EnumSet.of(DomainType.LOCAL_OS_DOMAIN));
        }
        Assert.assertNotNull(stores);
        Assert.assertTrue(stores.size() == 1);

        IIdentityStoreData store = stores.iterator().next();
        PrincipalId principal = new PrincipalId("root", store.getName());

        PersonUser person = idmClient.findPersonUser(tenantName, principal);
        Assert.assertNotNull(person);

        boolean bUserAdded = idmClient.addUserToGroup(tenantName, principal, "Administrators");
        Assert.assertTrue(bUserAdded);

        try {
            bUserAdded = false;
            bUserAdded = idmClient.addUserToGroup(tenantName, principal, "Administrators");
            Assert.assertTrue(bUserAdded);
        } catch (MemberAlreadyExistException e) {
            Assert.assertTrue(!bUserAdded);
        }

        Set<PersonUser> members = idmClient.findPersonUsersInGroup(tenantName,
                new PrincipalId("Administrators", tenantName), "", -1);
        Assert.assertTrue(members.contains(person));

        boolean bIsRemoved = idmClient.removeFromLocalGroup(tenantName, principal, "Administrators");
        Assert.assertTrue(bIsRemoved);

        members = idmClient.findPersonUsersInGroup(tenantName, new PrincipalId("Administrators", tenantName),
                "", -1);
        Assert.assertTrue(members == null || members.size() == 0 || !members.contains(person));
    }
}

From source file:com.vmware.identity.idm.client.TenantManagementTest.java

@TestOrderAnnotation(order = 26)
@Test//from   www .  j  ava 2s.  com
public void testAddRemoveLocalOsFsptestGroup() throws Exception, IDMException {
    if (SystemUtils.IS_OS_LINUX) {
        CasIdmClient idmClient = getIdmClient();

        String tenantName = idmClient.getDefaultTenant();
        Assert.assertNotNull(tenantName);

        Collection<IIdentityStoreData> stores = idmClient.getProviders(tenantName,
                EnumSet.of(DomainType.LOCAL_OS_DOMAIN));
        if (stores == null || stores.isEmpty()) {
            // add the localOs
            final String localOsDomainName = "localOsDomain";
            IIdentityStoreData localOsProvider = IdentityStoreData
                    .CreateLocalOSIdentityStoreData(localOsDomainName);
            idmClient.addProvider(tenantName, localOsProvider);

            stores = idmClient.getProviders(tenantName, EnumSet.of(DomainType.LOCAL_OS_DOMAIN));
        }
        Assert.assertNotNull(stores);
        Assert.assertTrue(stores.size() == 1);

        IIdentityStoreData store = stores.iterator().next();
        PrincipalId principal = new PrincipalId("root", store.getName());

        Group group = idmClient.findGroup(tenantName, principal);
        Assert.assertNotNull(group);

        boolean bGroupAdded = idmClient.addGroupToGroup(tenantName, principal, "Administrators");
        Assert.assertTrue(bGroupAdded);

        try {
            bGroupAdded = false;
            bGroupAdded = idmClient.addGroupToGroup(tenantName, principal, "Administrators");
            Assert.assertTrue(bGroupAdded);
        } catch (MemberAlreadyExistException e) {
            Assert.assertTrue(!bGroupAdded);
        }

        Set<Group> members = idmClient.findGroupsInGroup(tenantName,
                new PrincipalId("Administrators", tenantName), "", -1);
        Assert.assertTrue(members.contains(group));

        boolean bIsRemoved = idmClient.removeFromLocalGroup(tenantName, principal, "Administrators");
        Assert.assertTrue(bIsRemoved);

        members = idmClient.findGroupsInGroup(tenantName, new PrincipalId("Administrators", tenantName), "",
                -1);
        Assert.assertTrue(members == null || members.size() == 0 || !members.contains(group));
    }
}

From source file:com.vmware.identity.idm.server.IdentityManager.java

/**
 * Retrieves SPN in the form of HTTP/computername.domainname in case is
 * AD-joined, or the HTTP/computer name if not joined.
 *
 * Use case: WEBSSO server pass this information to logon page script for
 * windows session authentication.//  ww  w .  j ava  2 s  .  c o m
 *
 * @throws Exception
 *
 *@return
 *
 * null : If the machine is not joined AD or left AD domain <br/>
 * HTTP/computername.domainname : If machine is domain joined.
 */
@Override
public String getServerSPN() throws Exception {

    IIdmClientLibrary idmAdapter = IdmClientLibraryFactory.getInstance().getLibrary();

    String spn = null;
    try {
        ActiveDirectoryJoinInfo joinInfo = getActiveDirectoryJoinStatus();
        ActiveDirectoryJoinInfo.JoinStatus joinStatus = joinInfo.getJoinStatus();
        if (logger.isDebugEnabled()) {
            logger.debug("AD-joined status is",
                    (joinStatus == ActiveDirectoryJoinInfo.JoinStatus.ACTIVE_DIRECTORY_JOIN_STATUS_DOMAIN)
                            ? "joined"
                            : "not joined");
        }
        String domainName = (joinInfo
                .getJoinStatus() == ActiveDirectoryJoinInfo.JoinStatus.ACTIVE_DIRECTORY_JOIN_STATUS_DOMAIN)
                        ? joinInfo.getName()
                        : null;

        if (domainName != null && !domainName.isEmpty()) {
            if (SystemUtils.IS_OS_LINUX) {
                final String FQDN_CONFIG_KEY = "Services\\lsass\\Parameters\\Providers\\ActiveDirectory\\DomainJoin\\"
                        + domainName.toUpperCase() + "\\Pstore";

                IRegistryAdapter registryAdapter = RegistryAdapterFactory.getInstance().getRegistryAdapter();
                IRegistryKey rootRegistryKey = registryAdapter.openRootKey((int) RegKeyAccess.KEY_READ);
                String fqdn = null;

                try {
                    fqdn = registryAdapter.getStringValue(rootRegistryKey, FQDN_CONFIG_KEY, "Fqdn", true);
                } finally {
                    rootRegistryKey.close();
                }

                if (fqdn != null && !fqdn.isEmpty()) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Fqdn read from likewise regisry is: " + fqdn);
                    }

                    spn = "HTTP/" + fqdn;
                }
            } else {
                //Windows
                String computerName = idmAdapter.getComputerName();
                Validate.notEmpty(computerName);
                spn = "HTTP/" + computerName;
                spn += "." + domainName;
            }
        }
        return spn;
    } catch (Exception e) {
        logger.error("Failed to get service principal name");
        throw new IdmADDomainJoinStatusException("Failed to get service principal name in creating SPN", e);
    }

}

From source file:net.urosk.mifss.core.workers.converters.BaseMediaConverter.java

public String getOsAwarePath(String path) throws MediaConverterException {

    if (SystemUtils.IS_OS_LINUX) {
        return path;
    } else if (SystemUtils.IS_OS_WINDOWS) {
        return ("\"" + path + "\"");

    } else {/*from  ww w.  jav a 2s.c om*/
        throw new MediaConverterException("OS platform not supported ...");
    }
}

From source file:net.wimpi.modbus.net.SerialConnection.java

/**
 * Opens the communication port./*from  w  ww . jav a2 s. c o  m*/
 *
 * @throws Exception if an error occurs.
 */
public void open() throws Exception {

    // If this is Linux then first of all we need to check that 
    // device file exists. Otherwise call to m_PortIdentifyer.open()
    // method will crash JVM.
    // It is ugly patch but it is too late...
    if (SystemUtils.IS_OS_LINUX) {
        File portDevFile = new File(m_Parameters.getPortName());

        if (!portDevFile.exists()) {
            throw new Exception("Modbus serial device " + m_Parameters.getPortName() + " doesn't exist!");
        }
    }

    //1. obtain a CommPortIdentifier instance
    try {
        m_PortIdentifyer = CommPortIdentifier.getPortIdentifier(m_Parameters.getPortName());
    } catch (NoSuchPortException e) {
        final String errMsg = "Could not get port identifier, maybe insufficient permissions. "
                + e.getMessage();
        logger.debug(errMsg);
        throw new Exception(errMsg);
    }
    logger.trace("Got Port Identifier");

    //2. open the port, wait for given timeout
    try {
        m_SerialPort = (SerialPort) m_PortIdentifyer.open("Modbus Serial Master", 30000);
    } catch (PortInUseException e) {
        logger.debug("open port failed: " + e.getMessage());

        throw new Exception(e.getMessage());
    }
    logger.trace("Got Serial Port");

    //3. set the parameters
    try {
        setConnectionParameters();
    } catch (Exception e) {
        //ensure it is closed
        m_SerialPort.close();
        logger.debug("parameter setup failed: " + e.getMessage());
        throw e;
    }

    if (Modbus.SERIAL_ENCODING_ASCII.equals(m_Parameters.getEncoding())) {
        m_Transport = new ModbusASCIITransport();
    } else if (Modbus.SERIAL_ENCODING_RTU.equals(m_Parameters.getEncoding())) {
        m_Transport = new ModbusRTUTransport();
        setReceiveTimeout(m_Parameters.getReceiveTimeout()); //just here for the moment.
    } else if (Modbus.SERIAL_ENCODING_BIN.equals(m_Parameters.getEncoding())) {
        m_Transport = new ModbusBINTransport();
    }
    m_Transport.setEcho(m_Parameters.isEcho());

    // Open the input and output streams for the connection. If they won't
    // open, close the port before throwing an exception.
    try {
        m_SerialIn = m_SerialPort.getInputStream();
        m_Transport.setCommPort(m_SerialPort);
        //       m_Transport.prepareStreams(m_SerialIn,
        //                                  m_SerialPort.getOutputStream());
    } catch (IOException e) {
        m_SerialPort.close();
        logger.debug(e.getMessage());

        throw new Exception("Error opening i/o streams");
    }
    logger.trace("i/o Streams prepared");

    // Add this object as an event listener for the serial port.
    try {
        m_SerialPort.addEventListener(this);
    } catch (TooManyListenersException e) {
        m_SerialPort.close();
        final String errMsg = "too many listeners added";
        logger.debug("{}: {}", errMsg, e.getMessage());
        throw new Exception(errMsg);
    }

    // Set notifyOnBreakInterrup to allow event driven break handling.
    m_SerialPort.notifyOnBreakInterrupt(true);

    m_Open = true;
}

From source file:org.apache.bookkeeper.proto.BookieNettyServer.java

BookieNettyServer(ServerConfiguration conf, RequestProcessor processor)
        throws IOException, KeeperException, InterruptedException, BookieException {
    this.maxFrameSize = conf.getNettyMaxFrameSizeBytes();
    this.conf = conf;
    this.requestProcessor = processor;
    this.authProviderFactory = AuthProviderFactoryFactory.newBookieAuthProviderFactory(conf);

    if (!conf.isDisableServerSocketBind()) {
        ThreadFactory threadFactory = new DefaultThreadFactory("bookie-io");
        final int numThreads = conf.getServerNumIOThreads();

        EventLoopGroup eventLoopGroup;/*from  www  .  j av a 2s  .com*/
        if (SystemUtils.IS_OS_LINUX) {
            try {
                eventLoopGroup = new EpollEventLoopGroup(numThreads, threadFactory);
            } catch (ExceptionInInitializerError | NoClassDefFoundError | UnsatisfiedLinkError e) {
                LOG.warn("Could not use Netty Epoll event loop for bookie server: {}", e.getMessage());
                eventLoopGroup = new NioEventLoopGroup(numThreads, threadFactory);
            }
        } else {
            eventLoopGroup = new NioEventLoopGroup(numThreads, threadFactory);
        }

        this.eventLoopGroup = eventLoopGroup;
        allChannels = new CleanupChannelGroup(eventLoopGroup);
    } else {
        this.eventLoopGroup = null;
    }

    if (conf.isEnableLocalTransport()) {
        jvmEventLoopGroup = new DefaultEventLoopGroup();
        allChannels = new CleanupChannelGroup(jvmEventLoopGroup);
    } else {
        jvmEventLoopGroup = null;
    }

    bookieAddress = Bookie.getBookieAddress(conf);
    if (conf.getListeningInterface() == null) {
        bindAddress = new InetSocketAddress(conf.getBookiePort());
    } else {
        bindAddress = bookieAddress.getSocketAddress();
    }
    listenOn(bindAddress, bookieAddress);
}

From source file:org.apache.bookkeeper.util.EventLoopUtil.java

private static EventLoopGroup getEventLoopGroup(ThreadFactory threadFactory, int numThreads,
        boolean enableBusyWait) {
    if (!SystemUtils.IS_OS_LINUX) {
        return new NioEventLoopGroup(numThreads, threadFactory);
    }//from   w w w.  ja  v a  2s  . co  m

    try {
        if (!enableBusyWait) {
            // Regular Epoll based event loop
            return new EpollEventLoopGroup(numThreads, threadFactory);
        }

        // With low latency setting, put the Netty event loop on busy-wait loop to reduce cost of
        // context switches
        EpollEventLoopGroup eventLoopGroup = new EpollEventLoopGroup(numThreads, threadFactory,
                () -> (selectSupplier, hasTasks) -> SelectStrategy.BUSY_WAIT);

        // Enable CPU affinity on IO threads
        for (int i = 0; i < numThreads; i++) {
            eventLoopGroup.next().submit(() -> {
                try {
                    CpuAffinity.acquireCore();
                } catch (Throwable t) {
                    log.warn("Failed to acquire CPU core for thread {}", Thread.currentThread().getName(),
                            t.getMessage(), t);
                }
            });
        }

        return eventLoopGroup;
    } catch (ExceptionInInitializerError | NoClassDefFoundError | UnsatisfiedLinkError e) {
        log.warn("Could not use Netty Epoll event loop: {}", e.getMessage());
        return new NioEventLoopGroup(numThreads, threadFactory);
    }
}

From source file:org.apache.distributedlog.impl.BKNamespaceDriver.java

static EventLoopGroup getDefaultEventLoopGroup(int numThreads) {
    ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("DL-io-%s").build();
    if (SystemUtils.IS_OS_LINUX) {
        try {//from   ww  w. j  av  a2  s.  co  m
            return new EpollEventLoopGroup(numThreads, threadFactory);
        } catch (Throwable t) {
            LOG.warn("Could not use Netty Epoll event loop for bookie server:", t);
            return new NioEventLoopGroup(numThreads, threadFactory);
        }
    } else {
        return new NioEventLoopGroup(numThreads, threadFactory);
    }
}

From source file:org.apache.hadoop.crypto.random.TestOsSecureRandom.java

private static OsSecureRandom getOsSecureRandom() throws IOException {
    Assume.assumeTrue(SystemUtils.IS_OS_LINUX);
    OsSecureRandom random = new OsSecureRandom();
    random.setConf(new Configuration());
    return random;
}