private void setSvnCredential(CIJob job) throws JDOMException, IOException { S_LOGGER.debug("Entering Method CIManagerImpl.setSvnCredential"); try { String jenkinsTemplateDir = Utility.getJenkinsTemplateDir(); String credentialFilePath = jenkinsTemplateDir + job.getRepoType() + HYPHEN + CREDENTIAL_XML; if (debugEnabled) { S_LOGGER.debug("credentialFilePath ... " + credentialFilePath); } File credentialFile = new File(credentialFilePath); SvnProcessor processor = new SvnProcessor(credentialFile); // DataInputStream in = new DataInputStream(new FileInputStream(credentialFile)); // while (in.available() != 0) { // System.out.println(in.readLine()); // } // in.close(); processor.changeNodeValue("credentials/entry//userName", job.getUserName()); processor.changeNodeValue("credentials/entry//password", job.getPassword()); processor.writeStream(new File(Utility.getJenkinsHome() + File.separator + job.getName())); // jenkins home location String jenkinsJobHome = System.getenv(JENKINS_HOME); StringBuilder builder = new StringBuilder(jenkinsJobHome); builder.append(File.separator); processor.writeStream(new File(builder.toString() + CI_CREDENTIAL_XML)); } catch (Exception e) { S_LOGGER.error( "Entered into the catch block of CIManagerImpl.setSvnCredential " + e.getLocalizedMessage()); } }
static String cleanproperty(String property) { String value = System.getProperty(property); if (value != null) { value = value.trim(); if (value.length() == 0) value = null; } return value; }
static String getpassword(String prefix) { String password = System.getProperty(prefix + "storepassword"); if (password != null) { password = password.trim(); if (password.length() == 0) password = null; } return password; }
static String getstorepath(String prefix) { String path = System.getProperty(prefix + "store"); if (path != null) { path = path.trim(); if (path.length() == 0) path = null; } return path; }
public static void main(String args[]) throws Exception { int choice; BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Vishwa Based Campus Compute Cloud"); while (true) { System.out.println(""); if (username != null) { System.out.println("1. Logout"); } else { System.out.println("1. Login"); } System.out.println("2. Join the Grid"); System.out.println("3. Avail the compute facility"); System.out.println("4. Quit"); System.out.printf("Enter your choice: "); try { choice = Integer.parseInt(in.readLine()); } catch (NumberFormatException ex) { System.out.println("WARNING: Enter a number only!"); continue; } if (choice == 1) { if (username != null) { username = null; } else { System.out.printf("Enter your username: "******"Enter your password: "******"Successfully logged in!"); } else { System.out.println("Unable to login. Please check your credentials."); username = null; } } } else if (choice == 2) { share(); } else if (choice == 3) { compute(); } else { System.exit(0); } } }
private void setMailCredential(CIJob job) { if (debugEnabled) { S_LOGGER.debug("Entering Method CIManagerImpl.setMailCredential"); } try { String jenkinsTemplateDir = Utility.getJenkinsTemplateDir(); String mailFilePath = jenkinsTemplateDir + MAIL + HYPHEN + CREDENTIAL_XML; if (debugEnabled) { S_LOGGER.debug("configFilePath ... " + mailFilePath); } File mailFile = new File(mailFilePath); SvnProcessor processor = new SvnProcessor(mailFile); // DataInputStream in = new DataInputStream(new FileInputStream(mailFile)); // while (in.available() != 0) { // System.out.println(in.readLine()); // } // in.close(); // Mail have to go with jenkins running email address InetAddress ownIP = InetAddress.getLocalHost(); processor.changeNodeValue( CI_HUDSONURL, HTTP_PROTOCOL + PROTOCOL_POSTFIX + ownIP.getHostAddress() + COLON + job.getJenkinsPort() + FORWARD_SLASH + CI + FORWARD_SLASH); processor.changeNodeValue("smtpAuthUsername", job.getSenderEmailId()); processor.changeNodeValue("smtpAuthPassword", job.getSenderEmailPassword()); processor.changeNodeValue("adminAddress", job.getSenderEmailId()); // jenkins home location String jenkinsJobHome = System.getenv(JENKINS_HOME); StringBuilder builder = new StringBuilder(jenkinsJobHome); builder.append(File.separator); processor.writeStream(new File(builder.toString() + CI_MAILER_XML)); } catch (Exception e) { S_LOGGER.error( "Entered into the catch block of CIManagerImpl.setMailCredential " + e.getLocalizedMessage()); } }
public void postJsonToPipeline(String endpoint, List docs, int requestId) throws Exception { FusionSession fusionSession = null; long currTime = System.nanoTime(); synchronized (this) { fusionSession = sessions.get(endpoint); // ensure last request within the session timeout period, else reset the session if (fusionSession == null || (currTime - fusionSession.sessionEstablishedAt) > maxNanosOfInactivity) { log.info( "Fusion session is likely expired (or soon will be) for endpoint " + endpoint + ", " + "pre-emptively re-setting this session before processing request " + requestId); fusionSession = resetSession(endpoint); if (fusionSession == null) throw new IllegalStateException( "Failed to re-connect to " + endpoint + " after session loss when processing request " + requestId); } } HttpEntity entity = null; try { HttpPost postRequest = new HttpPost(endpoint); // stream the json directly to the HTTP output EntityTemplate et = new EntityTemplate(new JacksonContentProducer(jsonObjectMapper, docs)); et.setContentType("application/json; charset=utf-8"); et.setContentEncoding("gzip"); // StandardCharsets.UTF_8.name()); postRequest.setEntity(et); // new BufferedHttpEntity(et)); HttpClientContext context = HttpClientContext.create(); context.setCookieStore(cookieStore); HttpResponse response = httpClient.execute(postRequest, context); entity = response.getEntity(); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == 401) { // unauth'd - session probably expired? retry to establish log.warn( "Unauthorized error (401) when trying to send request " + requestId + " to Fusion at " + endpoint + ", will re-try to establish session"); // re-establish the session and re-try the request try { EntityUtils.consume(entity); } catch (Exception ignore) { log.warn("Failed to consume entity due to: " + ignore); } finally { entity = null; } synchronized (this) { fusionSession = resetSession(endpoint); if (fusionSession == null) throw new IllegalStateException( "After re-establishing session when processing request " + requestId + ", endpoint " + endpoint + " is no longer active! Try another endpoint."); } log.info( "Going to re-try request " + requestId + " after session re-established with " + endpoint); response = httpClient.execute(postRequest, context); entity = response.getEntity(); statusCode = response.getStatusLine().getStatusCode(); if (statusCode == 200 || statusCode == 204) { log.info( "Re-try request " + requestId + " after session timeout succeeded for: " + endpoint); } else { raiseFusionServerException(endpoint, entity, statusCode, response, requestId); } } else if (statusCode != 200 && statusCode != 204) { raiseFusionServerException(endpoint, entity, statusCode, response, requestId); } else { // OK! } } finally { if (entity != null) { try { EntityUtils.consume(entity); } catch (Exception ignore) { log.warn("Failed to consume entity due to: " + ignore); } finally { entity = null; } } } }
protected FusionSession establishSession(String url, String user, String password, String realm) throws Exception { FusionSession fusionSession = new FusionSession(); if (realm != null) { int at = url.indexOf("/api"); String proxyUrl = url.substring(0, at); String sessionApi = proxyUrl + "/api/session?realmName=" + realm; String jsonString = "{\"username\":\"" + user + "\", \"password\":\"" + password + "\"}"; // TODO: ugly! URL sessionApiUrl = new URL(sessionApi); String sessionHost = sessionApiUrl.getHost(); try { clearCookieForHost(sessionHost); } catch (Exception exc) { log.warn("Failed to clear session cookie for " + sessionHost + " due to: " + exc); } HttpPost postRequest = new HttpPost(sessionApiUrl.toURI()); postRequest.setEntity( new StringEntity( jsonString, ContentType.create("application/json", StandardCharsets.UTF_8))); HttpClientContext context = HttpClientContext.create(); context.setCookieStore(cookieStore); HttpResponse response = httpClient.execute(postRequest, context); HttpEntity entity = response.getEntity(); try { int statusCode = response.getStatusLine().getStatusCode(); if (statusCode != 200 && statusCode != 201 && statusCode != 204) { String body = extractResponseBodyText(entity); throw new SolrException( SolrException.ErrorCode.getErrorCode(statusCode), "POST credentials to Fusion Session API [" + sessionApi + "] failed due to: " + response.getStatusLine() + ": " + body); } else if (statusCode == 401) { // retry in case this is an expired error String body = extractResponseBodyText(entity); if (body != null && body.indexOf("session-idle-timeout") != -1) { EntityUtils.consume( entity); // have to consume the previous entity before re-trying the request log.warn( "Received session-idle-timeout error from Fusion Session API, re-trying to establish a new session to " + url); try { clearCookieForHost(sessionHost); } catch (Exception exc) { log.warn("Failed to clear session cookie for " + sessionHost + " due to: " + exc); } response = httpClient.execute(postRequest, context); entity = response.getEntity(); statusCode = response.getStatusLine().getStatusCode(); if (statusCode != 200 && statusCode != 201 && statusCode != 204) { body = extractResponseBodyText(entity); throw new SolrException( SolrException.ErrorCode.getErrorCode(statusCode), "POST credentials to Fusion Session API [" + sessionApi + "] failed due to: " + response.getStatusLine() + ": " + body); } } } } finally { if (entity != null) EntityUtils.consume(entity); } log.info( "Established secure session with Fusion Session API on " + url + " for user " + user + " in realm " + realm); } fusionSession.sessionEstablishedAt = System.nanoTime(); URL fusionUrl = new URL(url); String hostAndPort = fusionUrl.getHost() + ":" + fusionUrl.getPort(); return fusionSession; }