List of usage examples for org.joda.time DateTime toString
@ToString
public String toString()
From source file:io.druid.indexing.overlord.DbTaskStorage.java
License:Open Source License
@Override public List<TaskStatus> getRecentlyFinishedTaskStatuses() { final DateTime recent = new DateTime().minus(config.getRecentlyFinishedThreshold()); return retryingHandle(new HandleCallback<List<TaskStatus>>() { @Override/*from w ww. j a v a 2 s . c om*/ public List<TaskStatus> withHandle(Handle handle) throws Exception { final List<Map<String, Object>> dbTasks = handle.createQuery(String.format( "SELECT id, status_payload FROM %s WHERE active = 0 AND created_date >= :recent ORDER BY created_date DESC", dbTables.getTasksTable())).bind("recent", recent.toString()).list(); final ImmutableList.Builder<TaskStatus> statuses = ImmutableList.builder(); for (final Map<String, Object> row : dbTasks) { final String id = row.get("id").toString(); try { final TaskStatus status = jsonMapper.readValue((byte[]) row.get("status_payload"), TaskStatus.class); if (status.isComplete()) { statuses.add(status); } } catch (Exception e) { log.makeAlert(e, "Failed to parse status payload").addData("task", id).emit(); } } return statuses.build(); } }); }
From source file:io.druid.metadata.DerbyMetadataStorageActionHandler.java
License:Apache License
@Override protected Query<Map<String, Object>> createInactiveStatusesSinceQuery(Handle handle, DateTime timestamp, @Nullable Integer maxNumStatuses) { String sql = StringUtils.format( "SELECT " + " id, " + " status_payload " + "FROM " + " %s " + "WHERE " + " active = FALSE AND created_date >= :start " + "ORDER BY created_date DESC", getEntryTable());//from w ww . ja va 2 s . c om if (maxNumStatuses != null) { sql += " FETCH FIRST :n ROWS ONLY"; } Query<Map<String, Object>> query = handle.createQuery(sql).bind("start", timestamp.toString()); if (maxNumStatuses != null) { query = query.bind("n", maxNumStatuses); } return query; }
From source file:io.druid.metadata.MySQLMetadataStorageActionHandler.java
License:Apache License
@Override protected Query<Map<String, Object>> createInactiveStatusesSinceQuery(Handle handle, DateTime timestamp, @Nullable Integer maxNumStatuses) { String sql = StringUtils.format( "SELECT " + " id, " + " status_payload " + "FROM " + " %s " + "WHERE " + " active = FALSE AND created_date >= :start " + "ORDER BY created_date DESC", getEntryTable());/*from w w w . ja v a 2s .co m*/ if (maxNumStatuses != null) { sql += " LIMIT :n"; } Query<Map<String, Object>> query = handle.createQuery(sql).bind("start", timestamp.toString()); if (maxNumStatuses != null) { query = query.bind("n", maxNumStatuses); } return query; }
From source file:io.druid.metadata.SQLMetadataRuleManager.java
License:Apache License
public boolean overrideRule(final String dataSource, final List<Rule> newRules, final AuditInfo auditInfo) { final String ruleString; try {//from w w w . j ava2s.c o m ruleString = jsonMapper.writeValueAsString(newRules); log.info("Updating [%s] with rules [%s] as per [%s]", dataSource, ruleString, auditInfo); } catch (JsonProcessingException e) { log.error(e, "Unable to write rules as string for [%s]", dataSource); return false; } synchronized (lock) { try { dbi.inTransaction(new TransactionCallback<Void>() { @Override public Void inTransaction(Handle handle, TransactionStatus transactionStatus) throws Exception { final DateTime auditTime = DateTime.now(); auditManager.doAudit(AuditEntry.builder().key(dataSource).type("rules").auditInfo(auditInfo) .payload(ruleString).auditTime(auditTime).build(), handle); String version = auditTime.toString(); handle.createStatement(String.format( "INSERT INTO %s (id, dataSource, version, payload) VALUES (:id, :dataSource, :version, :payload)", getRulesTable())).bind("id", String.format("%s_%s", dataSource, version)) .bind("dataSource", dataSource).bind("version", version) .bind("payload", jsonMapper.writeValueAsBytes(newRules)).execute(); return null; } }); } catch (Exception e) { log.error(e, String.format("Exception while overriding rule for %s", dataSource)); return false; } } try { poll(); } catch (Exception e) { log.error(e, String.format("Exception while polling for rules after overriding the rule for %s", dataSource)); } return true; }
From source file:io.druid.metadata.SQLMetadataStorageActionHandler.java
License:Apache License
public void insert(final String id, final DateTime timestamp, final String dataSource, final EntryType entry, final boolean active, final StatusType status) throws EntryExistsException { try {//from www.java 2s .c o m connector.retryWithHandle(new HandleCallback<Void>() { @Override public Void withHandle(Handle handle) throws Exception { handle.createStatement(String.format( "INSERT INTO %s (id, created_date, datasource, payload, active, status_payload) VALUES (:id, :created_date, :datasource, :payload, :active, :status_payload)", entryTable)).bind("id", id).bind("created_date", timestamp.toString()) .bind("datasource", dataSource).bind("payload", jsonMapper.writeValueAsBytes(entry)) .bind("active", active).bind("status_payload", jsonMapper.writeValueAsBytes(status)) .execute(); return null; } }); } catch (Exception e) { final boolean isStatementException = e instanceof StatementException || (e instanceof CallbackFailedException && e.getCause() instanceof StatementException); if (isStatementException && getEntry(id).isPresent()) { throw new EntryExistsException(id, e); } else { throw Throwables.propagate(e); } } }
From source file:io.druid.metadata.SQLMetadataStorageActionHandler.java
License:Apache License
public List<StatusType> getInactiveStatusesSince(final DateTime timestamp) { return connector.retryWithHandle(new HandleCallback<List<StatusType>>() { @Override//from w ww . j a va2 s .c om public List<StatusType> withHandle(Handle handle) throws Exception { return handle.createQuery(String.format( "SELECT id, status_payload FROM %s WHERE active = FALSE AND created_date >= :start ORDER BY created_date DESC", entryTable)).bind("start", timestamp.toString()).map(new ResultSetMapper<StatusType>() { @Override public StatusType map(int index, ResultSet r, StatementContext ctx) throws SQLException { try { return jsonMapper.readValue(r.getBytes("status_payload"), statusType); } catch (IOException e) { log.makeAlert(e, "Failed to parse status payload") .addData("entry", r.getString("id")).emit(); throw new SQLException(e); } } }).list(); } }); }
From source file:io.druid.metadata.SQLServerMetadataStorageActionHandler.java
License:Apache License
@Override protected Query<Map<String, Object>> createInactiveStatusesSinceQuery(Handle handle, DateTime timestamp, @Nullable Integer maxNumStatuses) { String sql = maxNumStatuses == null ? "SELECT " : "SELECT TOP :n "; sql += StringUtils.format(//from www . j av a2s.c om " id, " + " status_payload " + "FROM " + " %s " + "WHERE " + " active = FALSE AND created_date >= :start " + "ORDER BY created_date DESC", getEntryTable()); Query<Map<String, Object>> query = handle.createQuery(sql).bind("start", timestamp.toString()); if (maxNumStatuses != null) { query = query.bind("n", maxNumStatuses); } return query; }
From source file:io.personium.common.auth.token.TransCellAccessToken.java
License:Apache License
/** * ?SAML????./*from ww w. j a va 2 s . c o m*/ * @return SAML */ public String toSamlString() { /* * Creation of SAML2.0 Document * http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf */ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); DocumentBuilder builder = null; try { builder = dbf.newDocumentBuilder(); } catch (ParserConfigurationException e) { // ???????????? throw new RuntimeException(e); } Document doc = builder.newDocument(); Element assertion = doc.createElementNS(URN_OASIS_NAMES_TC_SAML_2_0_ASSERTION, "Assertion"); doc.appendChild(assertion); assertion.setAttribute("ID", this.id); assertion.setAttribute("Version", "2.0"); // Dummy Date DateTime dateTime = new DateTime(this.issuedAt); assertion.setAttribute("IssueInstant", dateTime.toString()); // Issuer Element issuer = doc.createElement("Issuer"); issuer.setTextContent(this.issuer); assertion.appendChild(issuer); // Subject Element subject = doc.createElement("Subject"); Element nameId = doc.createElement("NameID"); nameId.setTextContent(this.subject); Element subjectConfirmation = doc.createElement("SubjectConfirmation"); subject.appendChild(nameId); subject.appendChild(subjectConfirmation); assertion.appendChild(subject); // Conditions Element conditions = doc.createElement("Conditions"); Element audienceRestriction = doc.createElement("AudienceRestriction"); for (String aud : new String[] { this.target, this.schema }) { Element audience = doc.createElement("Audience"); audience.setTextContent(aud); audienceRestriction.appendChild(audience); } conditions.appendChild(audienceRestriction); assertion.appendChild(conditions); // AuthnStatement Element authnStmt = doc.createElement("AuthnStatement"); authnStmt.setAttribute("AuthnInstant", dateTime.toString()); Element authnCtxt = doc.createElement("AuthnContext"); Element authnCtxtCr = doc.createElement("AuthnContextClassRef"); authnCtxtCr.setTextContent("urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport"); authnCtxt.appendChild(authnCtxtCr); authnStmt.appendChild(authnCtxt); assertion.appendChild(authnStmt); // AttributeStatement Element attrStmt = doc.createElement("AttributeStatement"); Element attribute = doc.createElement("Attribute"); for (Role role : this.roleList) { Element attrValue = doc.createElement("AttributeValue"); Attr attr = doc.createAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "type"); attr.setPrefix("xsi"); attr.setValue("string"); attrValue.setAttributeNodeNS(attr); attrValue.setTextContent(role.schemeCreateUrlForTranceCellToken(this.issuer)); attribute.appendChild(attrValue); } attrStmt.appendChild(attribute); assertion.appendChild(attrStmt); // Normalization doc.normalizeDocument(); // Dsig?? // Create a DOMSignContext and specify the RSA PrivateKey and // location of the resulting XMLSignature's parent element. DOMSignContext dsc = new DOMSignContext(privKey, doc.getDocumentElement()); // Create the XMLSignature, but don't sign it yet. XMLSignature signature = xmlSignatureFactory.newXMLSignature(signedInfo, keyInfo); // Marshal, generate, and sign the enveloped signature. try { signature.sign(dsc); // ? return PersoniumCoreUtils.nodeToString(doc.getDocumentElement()); } catch (MarshalException e1) { // DOM??????? throw new RuntimeException(e1); } catch (XMLSignatureException e1) { // ?????????? throw new RuntimeException(e1); } /* * ------------------------------------------------------------ * http://tools.ietf.org/html/draft-ietf-oauth-saml2-bearer-10 * ------------------------------------------------------------ 2.1. Using SAML Assertions as Authorization * Grants To use a SAML Bearer Assertion as an authorization grant, use the following parameter values and * encodings. The value of "grant_type" parameter MUST be "urn:ietf:params:oauth:grant-type:saml2-bearer" The * value of the "assertion" parameter MUST contain a single SAML 2.0 Assertion. The SAML Assertion XML data MUST * be encoded using base64url, where the encoding adheres to the definition in Section 5 of RFC4648 [RFC4648] * and where the padding bits are set to zero. To avoid the need for subsequent encoding steps (by "application/ * x-www-form-urlencoded" [W3C.REC-html401-19991224], for example), the base64url encoded data SHOULD NOT be * line wrapped and pad characters ("=") SHOULD NOT be included. */ }
From source file:main.java.miro.browser.browser.converters.DateTimeConverter.java
License:Open Source License
@Override public Object convert(Object fromObject) { if (fromObject == null) { return null; }/* w ww . java2 s . c om*/ DateTime dt = (DateTime) fromObject; return dt.toString(); }
From source file:monasca.api.domain.model.alarmstatehistory.AlarmStateHistory.java
License:Apache License
public AlarmStateHistory(String alarmId, List<MetricDefinition> metrics, AlarmState oldState, AlarmState newState, List<AlarmTransitionSubAlarm> subAlarms, String reason, String reasonData, DateTime timestamp) { this.alarmId = alarmId; this.setMetrics(metrics); this.oldState = oldState; this.newState = newState; this.subAlarms = subAlarms; this.reason = reason; this.reasonData = reasonData; this.timestamp = Conversions.variantToDateTime(timestamp); this.id = timestamp.toString(); }