Example usage for java.security PrivilegedAction PrivilegedAction

List of usage examples for java.security PrivilegedAction PrivilegedAction

Introduction

In this page you can find the example usage for java.security PrivilegedAction PrivilegedAction.

Prototype

PrivilegedAction

Source Link

Usage

From source file:org.apache.flink.yarn.YarnTaskManagerRunner.java

public static void main(final String[] args) throws IOException {
    Map<String, String> envs = System.getenv();
    final String yarnClientUsername = envs.get(Client.ENV_CLIENT_USERNAME);
    final String localDirs = envs.get(Environment.LOCAL_DIRS.key());

    // configure local directory
    final String[] newArgs = Arrays.copyOf(args, args.length + 2);
    newArgs[newArgs.length - 2] = "-" + TaskManager.ARG_CONF_DIR;
    newArgs[newArgs.length - 1] = localDirs;
    LOG.info("Setting log path " + localDirs);
    LOG.info("YARN daemon runs as '" + UserGroupInformation.getCurrentUser().getShortUserName() + "' setting"
            + " user to execute Flink TaskManager to '" + yarnClientUsername + "'");
    UserGroupInformation ugi = UserGroupInformation.createRemoteUser(yarnClientUsername);
    for (Token<? extends TokenIdentifier> toks : UserGroupInformation.getCurrentUser().getTokens()) {
        ugi.addToken(toks);/*  w ww  . ja v a 2 s .co m*/
    }
    ugi.doAs(new PrivilegedAction<Object>() {
        @Override
        public Object run() {
            try {
                TaskManager.main(newArgs);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }
    });
}

From source file:org.apache.flink.yarn.appMaster.YarnTaskManagerRunner.java

public static void main(final String[] args) throws IOException {
    Map<String, String> envs = System.getenv();
    final String yarnClientUsername = envs.get(Client.ENV_CLIENT_USERNAME);
    final String localDirs = envs.get(Environment.LOCAL_DIRS.key());

    // configure local directory
    final String[] newArgs = Arrays.copyOf(args, args.length + 2);
    newArgs[newArgs.length - 2] = "-" + TaskManager.ARG_CONF_DIR;
    newArgs[newArgs.length - 1] = localDirs;
    LOG.info("Setting log path " + localDirs);
    LOG.info("YARN daemon runs as '" + UserGroupInformation.getCurrentUser().getShortUserName() + "' setting"
            + " user to execute Flink TaskManager to '" + yarnClientUsername + "'");
    UserGroupInformation ugi = UserGroupInformation.createRemoteUser(yarnClientUsername);
    for (Token<? extends TokenIdentifier> toks : UserGroupInformation.getCurrentUser().getTokens()) {
        ugi.addToken(toks);// w  w w .j ava2 s.c o  m
    }
    ugi.doAs(new PrivilegedAction<Object>() {
        @Override
        public Object run() {
            try {
                TaskManager.main(newArgs);
            } catch (Exception e) {
                LOG.fatal("Error while running the TaskManager", e);
            }
            return null;
        }
    });
}

From source file:eu.stratosphere.yarn.YarnTaskManagerRunner.java

public static void main(final String[] args) throws IOException {
    Map<String, String> envs = System.getenv();
    final String yarnClientUsername = envs.get(Client.ENV_CLIENT_USERNAME);
    final String localDirs = envs.get(Environment.LOCAL_DIRS.key());

    // configure local directory
    final String[] newArgs = Arrays.copyOf(args, args.length + 2);
    newArgs[newArgs.length - 2] = "-" + TaskManager.ARG_CONF_DIR;
    newArgs[newArgs.length - 1] = localDirs;
    LOG.info("Setting log path " + localDirs);
    LOG.info("YARN daemon runs as '" + UserGroupInformation.getCurrentUser().getShortUserName() + "' setting"
            + " user to execute Stratosphere TaskManager to '" + yarnClientUsername + "'");
    UserGroupInformation ugi = UserGroupInformation.createRemoteUser(yarnClientUsername);
    for (Token<? extends TokenIdentifier> toks : UserGroupInformation.getCurrentUser().getTokens()) {
        ugi.addToken(toks);//  w w  w.  j  ava2s  .  c  o  m
    }
    ugi.doAs(new PrivilegedAction<Object>() {
        @Override
        public Object run() {
            try {
                TaskManager.main(newArgs);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }
    });
}

From source file:Main.java

static long getLastModified(final File f) {
    return ((Long) AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
            return new Long(f.lastModified());
        }//from  w ww  .j  av  a2s  .com
    })).longValue();
}

From source file:Main.java

private static String getPrivilegedProperty(final String property_name) {
    return AccessController.doPrivileged(new PrivilegedAction<String>() {
        public String run() {
            return System.getProperty(property_name);
        }//from   w  w w  .  ja va 2  s  .c om
    });
}

From source file:Main.java

/**
 * Gets a boolean property as a privileged action.
 *//*from  w  ww .j a  v  a2s.  com*/
public static boolean getPrivilegedBoolean(final String property_name) {
    return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
        public Boolean run() {
            return Boolean.getBoolean(property_name);
        }
    });
}

From source file:Utils.java

public static void makeAccessible(final AccessibleObject object) {
    if (!object.isAccessible()) {
        if (System.getSecurityManager() == null) {
            object.setAccessible(true);//  www  . j a  v a  2  s  .  c o  m
        } else {
            AccessController.doPrivileged(new PrivilegedAction<Object>() {

                public Object run() {
                    object.setAccessible(true);
                    return null;
                }
            });
        }
    }
}

From source file:Main.java

/**
 * Gets an integer property as a privileged action.
 *
 * @param property_name the integer property name
 *
 * @return the property value/*from  w  w  w.j  av  a2s .  c om*/
 */
public static Integer getPrivilegedInteger(final String property_name) {
    return AccessController.doPrivileged(new PrivilegedAction<Integer>() {
        public Integer run() {
            return Integer.getInteger(property_name);
        }
    });
}

From source file:Main.java

private static void setField(final Object bean, final Field field, final Object value) throws Exception {
    if (!field.isAccessible()) {
        AccessController.doPrivileged(new PrivilegedAction<Void>() {
            public Void run() {
                field.setAccessible(true);
                return null;
            }/*from   w  w  w  .  j a  va  2 s  . c  o m*/
        });
    }
    field.set(bean, value);
}

From source file:Main.java

/**
 * Gets an integer property as a privileged action.
 *
 * @param property_name the integer property name
 * @param default_val   the default value to use if the property is not defined
 *
 * @return the property value//from  w ww .j a  va 2 s  .c  o  m
 */
public static Integer getPrivilegedInteger(final String property_name, final int default_val) {
    return AccessController.doPrivileged(new PrivilegedAction<Integer>() {
        public Integer run() {
            return Integer.getInteger(property_name, default_val);
        }
    });
}