List of usage examples for java.io IOException getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:org.apache.hadoop.yarn.server.resourcemanager.TestClientRMTokens.java
@Test public void testDelegationToken() throws IOException, InterruptedException { final YarnConfiguration conf = new YarnConfiguration(); conf.set(YarnConfiguration.RM_PRINCIPAL, "testuser/localhost@apache.org"); conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION, "kerberos"); UserGroupInformation.setConfiguration(conf); ResourceScheduler scheduler = createMockScheduler(conf); long initialInterval = 10000l; long maxLifetime = 20000l; long renewInterval = 10000l; RMDelegationTokenSecretManager rmDtSecretManager = createRMDelegationTokenSecretManager(initialInterval, maxLifetime, renewInterval); rmDtSecretManager.startThreads();//from ww w. j av a 2s .c o m LOG.info("Creating DelegationTokenSecretManager with initialInterval: " + initialInterval + ", maxLifetime: " + maxLifetime + ", renewInterval: " + renewInterval); final ClientRMService clientRMService = new ClientRMServiceForTest(conf, scheduler, rmDtSecretManager); clientRMService.init(conf); clientRMService.start(); ApplicationClientProtocol clientRMWithDT = null; try { // Create a user for the renewr and fake the authentication-method UserGroupInformation loggedInUser = UserGroupInformation.createRemoteUser("testrenewer@APACHE.ORG"); Assert.assertEquals("testrenewer", loggedInUser.getShortUserName()); // Default realm is APACHE.ORG loggedInUser.setAuthenticationMethod(AuthenticationMethod.KERBEROS); org.apache.hadoop.yarn.api.records.Token token = getDelegationToken(loggedInUser, clientRMService, loggedInUser.getShortUserName()); long tokenFetchTime = System.currentTimeMillis(); LOG.info("Got delegation token at: " + tokenFetchTime); // Now try talking to RMService using the delegation token clientRMWithDT = getClientRMProtocolWithDT(token, clientRMService.getBindAddress(), "loginuser1", conf); GetNewApplicationRequest request = Records.newRecord(GetNewApplicationRequest.class); try { clientRMWithDT.getNewApplication(request); } catch (IOException e) { fail("Unexpected exception" + e); } catch (YarnException e) { fail("Unexpected exception" + e); } // Renew after 50% of token age. while (System.currentTimeMillis() < tokenFetchTime + initialInterval / 2) { Thread.sleep(500l); } long nextExpTime = renewDelegationToken(loggedInUser, clientRMService, token); long renewalTime = System.currentTimeMillis(); LOG.info("Renewed token at: " + renewalTime + ", NextExpiryTime: " + nextExpTime); // Wait for first expiry, but before renewed expiry. while (System.currentTimeMillis() > tokenFetchTime + initialInterval && System.currentTimeMillis() < nextExpTime) { Thread.sleep(500l); } Thread.sleep(50l); // Valid token because of renewal. try { clientRMWithDT.getNewApplication(request); } catch (IOException e) { fail("Unexpected exception" + e); } catch (YarnException e) { fail("Unexpected exception" + e); } // Wait for expiry. while (System.currentTimeMillis() < renewalTime + renewInterval) { Thread.sleep(500l); } Thread.sleep(50l); LOG.info("At time: " + System.currentTimeMillis() + ", token should be invalid"); // Token should have expired. try { clientRMWithDT.getNewApplication(request); fail("Should not have succeeded with an expired token"); } catch (Exception e) { assertEquals(InvalidToken.class.getName(), e.getClass().getName()); assertTrue(e.getMessage().contains("is expired")); } // Test cancellation // Stop the existing proxy, start another. if (clientRMWithDT != null) { RPC.stopProxy(clientRMWithDT); clientRMWithDT = null; } token = getDelegationToken(loggedInUser, clientRMService, loggedInUser.getShortUserName()); tokenFetchTime = System.currentTimeMillis(); LOG.info("Got delegation token at: " + tokenFetchTime); // Now try talking to RMService using the delegation token clientRMWithDT = getClientRMProtocolWithDT(token, clientRMService.getBindAddress(), "loginuser2", conf); request = Records.newRecord(GetNewApplicationRequest.class); try { clientRMWithDT.getNewApplication(request); } catch (IOException e) { fail("Unexpected exception" + e); } catch (YarnException e) { fail("Unexpected exception" + e); } cancelDelegationToken(loggedInUser, clientRMService, token); if (clientRMWithDT != null) { RPC.stopProxy(clientRMWithDT); clientRMWithDT = null; } // Creating a new connection. clientRMWithDT = getClientRMProtocolWithDT(token, clientRMService.getBindAddress(), "loginuser2", conf); LOG.info("Cancelled delegation token at: " + System.currentTimeMillis()); // Verify cancellation worked. try { clientRMWithDT.getNewApplication(request); fail("Should not have succeeded with a cancelled delegation token"); } catch (IOException e) { } catch (YarnException e) { } // Test new version token // Stop the existing proxy, start another. if (clientRMWithDT != null) { RPC.stopProxy(clientRMWithDT); clientRMWithDT = null; } token = getDelegationToken(loggedInUser, clientRMService, loggedInUser.getShortUserName()); byte[] tokenIdentifierContent = token.getIdentifier().array(); RMDelegationTokenIdentifier tokenIdentifier = new RMDelegationTokenIdentifier(); DataInputBuffer dib = new DataInputBuffer(); dib.reset(tokenIdentifierContent, tokenIdentifierContent.length); tokenIdentifier.readFields(dib); // Construct new version RMDelegationTokenIdentifier with additional field RMDelegationTokenIdentifierForTest newVersionTokenIdentifier = new RMDelegationTokenIdentifierForTest( tokenIdentifier, "message"); Token<RMDelegationTokenIdentifier> newRMDTtoken = new Token<RMDelegationTokenIdentifier>( newVersionTokenIdentifier, rmDtSecretManager); org.apache.hadoop.yarn.api.records.Token newToken = BuilderUtils.newDelegationToken( newRMDTtoken.getIdentifier(), newRMDTtoken.getKind().toString(), newRMDTtoken.getPassword(), newRMDTtoken.getService().toString()); // Now try talking to RMService using the new version delegation token clientRMWithDT = getClientRMProtocolWithDT(newToken, clientRMService.getBindAddress(), "loginuser3", conf); request = Records.newRecord(GetNewApplicationRequest.class); try { clientRMWithDT.getNewApplication(request); } catch (IOException e) { fail("Unexpected exception" + e); } catch (YarnException e) { fail("Unexpected exception" + e); } } finally { rmDtSecretManager.stopThreads(); // TODO PRECOMMIT Close proxies. if (clientRMWithDT != null) { RPC.stopProxy(clientRMWithDT); } } }
From source file:org.codehaus.mojo.antlr.AbstractAntlrMojo.java
protected void performGeneration(GenerationPlan plan, Artifact antlrArtifact) throws MojoExecutionException { if (!plan.getGenerationDirectory().getParentFile().exists()) { plan.getGenerationDirectory().getParentFile().mkdirs(); }// ww w . ja v a 2 s . c o m // ---------------------------------------------------------------------- // Wrap arguments // Note: grammar file should be last // ---------------------------------------------------------------------- List arguments = new LinkedList(); addArgIf(arguments, debug, "-debug"); addArgIf(arguments, diagnostic, "-diagnostic"); addArgIf(arguments, trace, "-trace"); addArgIf(arguments, traceParser, "-traceParser"); addArgIf(arguments, traceLexer, "-traceLexer"); addArgIf(arguments, traceTreeParser, "-traceTreeParser"); addArgs(arguments); arguments.add("-o"); arguments.add(plan.getGenerationDirectory().getPath()); if (plan.getCollectedSuperGrammarIds().size() > 0) { arguments.add("-glib"); StringBuffer buffer = new StringBuffer(); Iterator ids = plan.getCollectedSuperGrammarIds().iterator(); while (ids.hasNext()) { buffer.append(new File(sourceDirectory, (String) ids.next())); if (ids.hasNext()) { buffer.append(';'); } } arguments.add(buffer.toString()); } arguments.add(plan.getSource().getPath()); String[] args = (String[]) arguments.toArray(new String[arguments.size()]); if (plan.getImportVocabTokenTypesDirectory() != null && !plan.getImportVocabTokenTypesDirectory().equals(plan.getGenerationDirectory())) { // we need to spawn a new process to properly set up PWD CommandLine commandLine = new CommandLine("java"); commandLine.addArgument("-classpath", false); commandLine.addArgument(generateClasspathForProcessSpawning(antlrArtifact), true); commandLine.addArgument("antlr.Tool", false); commandLine.addArguments(args, true); DefaultExecutor executor = new DefaultExecutor(); executor.setWorkingDirectory(plan.getImportVocabTokenTypesDirectory()); try { executor.execute(commandLine); } catch (IOException e) { getLog().warn("Error spawning process to execute antlr tool : " + e.getMessage()); } return; } // ---------------------------------------------------------------------- // Call Antlr // ---------------------------------------------------------------------- if (getLog().isDebugEnabled()) { getLog().debug("antlr args=\n" + StringUtils.join(args, "\n")); } boolean failedSetManager = false; SecurityManager oldSm = null; try { oldSm = System.getSecurityManager(); System.setSecurityManager(NoExitSecurityManager.INSTANCE); } catch (SecurityException ex) { // ANTLR-12 oldSm = null; failedSetManager = true; // ignore, in embedded environment the security manager can already be set. // in such a case assume the exit call is handled properly.. getLog().warn("Cannot set custom SecurityManager. " + "Antlr's call to System.exit() can cause application shutdown " + "if not handled by the current SecurityManager."); } String originalUserDir = null; if (plan.getImportVocabTokenTypesDirectory() != null) { originalUserDir = System.getProperty("user.dir"); System.setProperty("user.dir", plan.getImportVocabTokenTypesDirectory().getPath()); } PrintStream oldErr = System.err; OutputStream errOS = new StringOutputStream(); PrintStream err = new PrintStream(errOS); System.setErr(err); try { executeAntlrInIsolatedClassLoader((String[]) arguments.toArray(new String[0]), antlrArtifact); } catch (SecurityException e) { if (e.getMessage().equals("exitVM-0") || e.getClass().getName().equals("org.netbeans.core.execution.ExitSecurityException")) // netbeans // IDE Sec // Manager. { // ANTLR-12 // now basically every secutiry manager could set different message, how to handle in generic way? // probably only by external execution // / in case of NetBeans SecurityManager, it's not possible to distinguish exit codes, rather swallow // than fail. getLog().debug(e); } else { throw new MojoExecutionException( "Antlr execution failed: " + e.getMessage() + "\n Error output:\n" + errOS, e); } } finally { if (originalUserDir != null) { System.setProperty("user.dir", originalUserDir); } if (!failedSetManager) { System.setSecurityManager(oldSm); } System.setErr(oldErr); System.err.println(errOS.toString()); } }
From source file:org.apache.hadoop.hive.ql.MultiDriver.java
private void multiOutputResult() throws CommandNeedRetryException { //test output //output the result of the multiquery // set the var:plan schema ctx SessionState ss = SessionState.get(); PrintStream out = ss.out;//from w w w.jav a2 s . c om ArrayList<String> res = new ArrayList<String>(); LOG.info("Output the result of Multi-query"); try { boolean isexplain = ctx.getExplain(); if (isexplain) { LOG.info("Output explain query plan:"); printHeader(this, out); int counter = 0; while (this.getResults(res)) { for (String r : res) { out.println(r); } counter += res.size(); res.clear(); if (out.checkError()) { break; } } return; } int i; for (i = 0; i < multiPctx.size(); i++) { System.out.println("Output Multi-query ID:" + i); int counter = 0; if (!isexplain) { schema = schemas.get(i); } else { //schema=null; } printHeader(this, out); if (plan != null && ((MultiQueryPlan) plan).getfetchtasklist() != null) { plan.setFetchTask(((MultiQueryPlan) plan).getfetchtasklist().get(i)); } this.ctx = multiPctx.get(i).getContext(); while (this.getResults(res)) { for (String r : res) { out.println(r); } counter += res.size(); res.clear(); if (out.checkError()) { break; } } } } catch (IOException e) { console.printError("Failed with exception " + e.getClass().getName() + ":" + e.getMessage(), "\n" + org.apache.hadoop.util.StringUtils.stringifyException(e)); // ret = 1; } }
From source file:org.apache.hadoop.hive.ql.MultiDriver.java
private void multiOutputexplain() throws CommandNeedRetryException { //test output //output the result of the multiquery // set the var:plan schema ctx SessionState ss = SessionState.get(); PrintStream out = ss.out;//from www .jav a 2 s .co m ArrayList<String> res = new ArrayList<String>(); LOG.info("Output the result of Multi-query"); try { boolean isexplain = ctx.getExplain(); if (true) { LOG.info("Output explain query plan:"); printHeader(this, out); int counter = 0; while (this.getResults(res)) { for (String r : res) { out.println(r); } counter += res.size(); res.clear(); if (out.checkError()) { break; } } return; } int i; for (i = 0; i < multiPctx.size(); i++) { LOG.info("Output Multi-query ID:" + i); int counter = 0; if (!isexplain) { schema = schemas.get(i); } else { //schema=null; } printHeader(this, out); if (plan != null && ((MultiQueryPlan) plan).getfetchtasklist() != null) { plan.setFetchTask(((MultiQueryPlan) plan).getfetchtasklist().get(i)); } this.ctx = multiPctx.get(i).getContext(); while (this.getResults(res)) { for (String r : res) { out.println(r); } counter += res.size(); res.clear(); if (out.checkError()) { break; } } } } catch (IOException e) { console.printError("Failed with exception " + e.getClass().getName() + ":" + e.getMessage(), "\n" + org.apache.hadoop.util.StringUtils.stringifyException(e)); // ret = 1; } }
From source file:edu.umass.cs.reconfiguration.Reconfigurator.java
private void sendReconfigureRCNodeConfigConfirmationToInitiator(RCRecordRequest<NodeIDType> rcRecReq) { try {//from ww w. j a va 2 s . c om ReconfigureRCNodeConfig<NodeIDType> response = new ReconfigureRCNodeConfig<NodeIDType>( this.DB.getMyID(), rcRecReq.startEpoch.newlyAddedNodes, this.diff(rcRecReq.startEpoch.prevEpochGroup, rcRecReq.startEpoch.curEpochGroup)); log.log(Level.INFO, "\n\n{0}\n{1} sending {2} confirmation to {3}: {4}\n{5}", new Object[] { separator, this, ReconfigurationPacket.PacketType.RECONFIGURE_RC_NODE_CONFIG, rcRecReq.startEpoch.creator, response.getSummary(), separator }); (this.messenger).sendToAddress(rcRecReq.startEpoch.creator, new JSONMessenger.JSONObjectByteableWrapper(response // .toJSONObject() )); } catch (IOException /* | JSONException */ e) { log.severe(this + " incurred " + e.getClass().getSimpleName() + e.getMessage()); e.printStackTrace(); } }
From source file:edu.umass.cs.reconfiguration.Reconfigurator.java
private void sendReconfigureActiveNodeConfigConfirmationToInitiator(RCRecordRequest<NodeIDType> rcRecReq) { try {/* w ww .j a v a2 s .com*/ ReconfigureActiveNodeConfig<NodeIDType> response = new ReconfigureActiveNodeConfig<NodeIDType>( this.DB.getMyID(), rcRecReq.startEpoch.newlyAddedNodes, this.diff(rcRecReq.startEpoch.prevEpochGroup, rcRecReq.startEpoch.curEpochGroup)); log.log(Level.INFO, "{0} has nodeConfig = {1} after processing {2}", new Object[] { this, this.consistentNodeConfig, response.getSummary() }); log.log(Level.INFO, "\n\n{0}\n{1} finished required reconfigurations to change active replica(s) {2}; sending response to {3}\n{4}\n", new Object[] { separator, this, response.getSummary(), rcRecReq.startEpoch.creator, separator }); (this.messenger).sendToAddress(rcRecReq.startEpoch.creator, new JSONMessenger.JSONObjectByteableWrapper(response // .toJSONObject() )); } catch (IOException /* | JSONException */ e) { log.severe(this + " incurred " + e.getClass().getSimpleName() + e.getMessage()); e.printStackTrace(); } }
From source file:edu.umass.cs.reconfiguration.Reconfigurator.java
private boolean sendClientReconfigurationPacket(ClientReconfigurationPacket response) { try {/*from w w w . j a v a 2s. co m*/ InetSocketAddress querier = this.getQuerier(response); if (querier.equals(response.getCreator())) { // only response can go back to client log.log(Level.INFO, "{0} sending client RESPONSE {1}:{2} back to client", new Object[] { this, response.getSummary(), response.getResponseMessage(), querier }); (this.getClientMessenger(response.getMyReceiver())).sendToAddress(querier, new JSONMessenger.JSONObjectByteableWrapper(response // .toJSONObject() )); } else { // may be a request or response log.log(Level.INFO, "{0} sending {1} {2} to reconfigurator {3}", new Object[] { this, response.isRequest() ? "request" : "RESPONSE", response.getSummary(), querier }); assert (this.messenger.sendToAddress(querier, new JSONMessenger.JSONObjectByteableWrapper(response // .toJSONObject() )) > 0); } } catch (IOException /* | JSONException */ e) { log.severe(this + " incurred " + e.getClass().getSimpleName() + e.getMessage()); e.printStackTrace(); } return true; }
From source file:edu.umass.cs.reconfiguration.Reconfigurator.java
private boolean forwardClientReconfigurationPacket(ClientReconfigurationPacket request) { try {//ww w .j a v a 2 s . c o m Set<NodeIDType> responsibleRCs = this.DB.removeDead(new HashSet<NodeIDType>( this.consistentNodeConfig.getReplicatedReconfigurators(request.getServiceName()))); if (responsibleRCs.isEmpty()) return false; @SuppressWarnings("unchecked") NodeIDType randomResponsibleRC = (NodeIDType) (responsibleRCs .toArray()[(int) (Math.random() * responsibleRCs.size())]); request = request.setForwader(this.consistentNodeConfig.getBindSocketAddress(getMyID())); log.log(Level.INFO, "{0} forwarding client request {1} to reconfigurator {2}:{3}", new Object[] { this, request.getSummary(), randomResponsibleRC, this.consistentNodeConfig.getNodeSocketAddress(randomResponsibleRC) }); this.messenger.sendToAddress(this.consistentNodeConfig.getNodeSocketAddress(randomResponsibleRC), new JSONMessenger.JSONObjectByteableWrapper( request.setForwader(this.consistentNodeConfig.getNodeSocketAddress(getMyID())) // .toJSONObject() )); } catch (IOException /* | JSONException */ e) { log.severe(this + " incurred " + e.getClass().getSimpleName() + e.getMessage()); e.printStackTrace(); } return true; }
From source file:edu.umass.cs.reconfiguration.Reconfigurator.java
private void sendDeleteConfirmationToClient(RCRecordRequest<NodeIDType> rcRecReq) { if (rcRecReq.startEpoch.creator == null || !rcRecReq.getInitiator().equals(getMyID())) return;/* w ww . j a v a 2 s . c o m*/ try { InetSocketAddress querier = this.getQuerier(rcRecReq); // copy forwarder from startEpoch and mark as response DeleteServiceName response = (DeleteServiceName) new DeleteServiceName(rcRecReq.startEpoch.creator, rcRecReq.getServiceName(), rcRecReq.getEpochNumber() - 1, rcRecReq.startEpoch.getMyReceiver()) .setForwader(rcRecReq.startEpoch.getForwarder()).makeResponse(); if (querier.equals(rcRecReq.startEpoch.creator)) { log.log(Level.FINE, "{0} sending deletion confirmation {1} back to client", new Object[] { this, response.getSummary(), querier }); // this.getClientMessenger() (this.getMessenger(rcRecReq.startEpoch.getMyReceiver())).sendToAddress(this.getQuerier(rcRecReq), new JSONMessenger.JSONObjectByteableWrapper(response // .toJSONObject() )); } else { log.log(Level.FINE, "{0} sending deletion confirmation {1} to forwarding reconfigurator {2}", new Object[] { this, response.getSummary(), querier }); this.messenger.sendToAddress(querier, new JSONMessenger.JSONObjectByteableWrapper(response // .toJSONObject() )); } } catch (IOException /* | JSONException */ e) { log.severe(this + " incurred " + e.getClass().getSimpleName() + e.getMessage()); e.printStackTrace(); } }
From source file:edu.umass.cs.reconfiguration.Reconfigurator.java
private void sendCreateConfirmationToClient(RCRecordRequest<NodeIDType> rcRecReq, String headName) { if (rcRecReq.startEpoch.creator == null || !rcRecReq.getInitiator().equals(getMyID()) || headName == null) { return;//from w ww .j a va 2 s . c om } DelayProfiler.updateDelay(ProfilerKeys.create.toString(), rcRecReq.startEpoch.getInitTime()); try { InetSocketAddress querier = this.getQuerier(rcRecReq); CreateServiceName response = (CreateServiceName) (new CreateServiceName(rcRecReq.startEpoch.creator, headName, rcRecReq.getEpochNumber(), null, rcRecReq.startEpoch.getMyReceiver())) .setForwader(rcRecReq.startEpoch.getForwarder()).makeResponse(); // need to use different messengers for client and forwarder if (querier.equals(rcRecReq.startEpoch.creator)) { log.log(Level.INFO, "{0} sending creation confirmation {1} back to client", new Object[] { this, response.getSummary(), querier }); // this.getClientMessenger() (this.getMessenger(rcRecReq.startEpoch.getMyReceiver())).sendToAddress(querier, new JSONMessenger.JSONObjectByteableWrapper(response // .toJSONObject() )); } else { log.log(Level.INFO, "{0} sending creation confirmation {1} to forwarding reconfigurator {2}", new Object[] { this, response.getSummary(), querier }); this.messenger.sendToAddress(querier, new JSONMessenger.JSONObjectByteableWrapper( response.setForwardee(this.consistentNodeConfig.getNodeSocketAddress(getMyID())) // .toJSONObject() )); } } catch (IOException /* | JSONException */ e) { log.severe(this + " incurred " + e.getClass().getSimpleName() + e.getMessage()); e.printStackTrace(); } }