List of usage examples for org.joda.time.format ISODateTimeFormat dateTime
public static DateTimeFormatter dateTime()
From source file:com.google.cloud.dns.ChangeRequestInfo.java
License:Open Source License
Change toPb() { Change pb = new Change(); // set id//w w w . j a va 2 s. c om if (generatedId() != null) { pb.setId(generatedId()); } // set timestamp if (startTimeMillis() != null) { pb.setStartTime(ISODateTimeFormat.dateTime().withZoneUTC().print(startTimeMillis())); } // set status if (status() != null) { pb.setStatus(status().name().toLowerCase()); } // set a list of additions pb.setAdditions(Lists.transform(additions(), RecordSet.TO_PB_FUNCTION)); // set a list of deletions pb.setDeletions(Lists.transform(deletions(), RecordSet.TO_PB_FUNCTION)); return pb; }
From source file:com.google.cloud.dns.testing.LocalDnsHelper.java
License:Open Source License
/** * Creates new managed zone and stores it in the collection. Assumes that project exists. *//*from ww w.j ava 2 s.c o m*/ @VisibleForTesting Response createZone(String projectId, ManagedZone zone, String... fields) { Response errorResponse = checkZone(zone); if (errorResponse != null) { return errorResponse; } ManagedZone completeZone = new ManagedZone(); completeZone.setName(zone.getName()); completeZone.setDnsName(zone.getDnsName()); completeZone.setDescription(zone.getDescription()); completeZone.setNameServerSet(zone.getNameServerSet()); completeZone.setCreationTime(ISODateTimeFormat.dateTime().withZoneUTC().print(System.currentTimeMillis())); completeZone.setId(BigInteger.valueOf(Math.abs(ID_GENERATOR.nextLong() % Long.MAX_VALUE))); completeZone.setNameServers(randomNameservers()); ZoneContainer zoneContainer = new ZoneContainer(completeZone); ImmutableSortedMap<String, ResourceRecordSet> defaultsRecords = defaultRecords(completeZone); zoneContainer.dnsRecords().set(defaultsRecords); Change change = new Change(); change.setAdditions(ImmutableList.copyOf(defaultsRecords.values())); change.setStatus("done"); change.setId("0"); change.setStartTime(ISODateTimeFormat.dateTime().withZoneUTC().print(System.currentTimeMillis())); zoneContainer.changes().add(change); ProjectContainer projectContainer = findProject(projectId); ZoneContainer oldValue = projectContainer.zones().putIfAbsent(completeZone.getName(), zoneContainer); if (oldValue != null) { return Error.ALREADY_EXISTS.response(String .format("The resource 'entity.managedZone' named '%s' already exists", completeZone.getName())); } ManagedZone result = OptionParsers.extractFields(completeZone, fields); try { return new Response(HTTP_OK, jsonFactory.toString(result)); } catch (IOException e) { return Error.INTERNAL_ERROR .response(String.format("Error when serializing managed zone %s.", result.getName())); } }
From source file:com.google.cloud.dns.testing.LocalDnsHelper.java
License:Open Source License
/** * Creates a new change, stores it, and if delayChange > 0, invokes processing in a new thread. *///w w w.ja va 2 s .c om Response createChange(String projectId, String zoneName, Change change, String... fields) { ZoneContainer zoneContainer = findZone(projectId, zoneName); if (zoneContainer == null) { return Error.NOT_FOUND.response( String.format("The 'parameters.managedZone' resource named %s does not exist.", zoneName)); } Response response = checkChange(change, zoneContainer); if (response != null) { return response; } Change completeChange = new Change(); if (change.getAdditions() != null) { completeChange.setAdditions(ImmutableList.copyOf(change.getAdditions())); } if (change.getDeletions() != null) { completeChange.setDeletions(ImmutableList.copyOf(change.getDeletions())); } /* We need to set ID for the change. We are working in concurrent environment. We know that the element fell on an index between 1 and maxId (index 0 is the default change which creates SOA and NS), so we will reset all IDs between 0 and maxId (all of them are valid for the respective objects). */ ConcurrentLinkedQueue<Change> changeSequence = zoneContainer.changes(); changeSequence.add(completeChange); int maxId = changeSequence.size(); int index = 0; for (Change c : changeSequence) { if (index == maxId) { break; } c.setId(String.valueOf(index++)); } completeChange.setStatus("pending"); completeChange.setStartTime(ISODateTimeFormat.dateTime().withZoneUTC().print(System.currentTimeMillis())); invokeChange(projectId, zoneName, completeChange.getId()); Change result = OptionParsers.extractFields(completeChange, fields); try { return new Response(HTTP_OK, jsonFactory.toString(result)); } catch (IOException e) { return Error.INTERNAL_ERROR .response(String.format("Error when serializing change %s in managed zone %s in project %s.", result.getId(), zoneName, projectId)); } }
From source file:com.google.cloud.dns.ZoneInfo.java
License:Open Source License
ManagedZone toPb() { ManagedZone pb = new ManagedZone(); pb.setDescription(this.description()); pb.setDnsName(this.dnsName()); if (this.generatedId() != null) { pb.setId(new BigInteger(this.generatedId())); }/*from www . j ava 2 s . c o m*/ pb.setName(this.name()); pb.setNameServers(this.nameServers); // do use real attribute value which may be null pb.setNameServerSet(this.nameServerSet()); if (this.creationTimeMillis() != null) { pb.setCreationTime(ISODateTimeFormat.dateTime().withZoneUTC().print(this.creationTimeMillis())); } return pb; }
From source file:com.google.cloud.resourcemanager.ProjectInfo.java
License:Open Source License
com.google.api.services.cloudresourcemanager.model.Project toPb() { com.google.api.services.cloudresourcemanager.model.Project projectPb = new com.google.api.services.cloudresourcemanager.model.Project(); projectPb.setName(name);/*from w w w. j a v a 2s .co m*/ projectPb.setProjectId(projectId); projectPb.setLabels(labels); projectPb.setProjectNumber(projectNumber); if (state != null) { projectPb.setLifecycleState(state.toString()); } if (createTimeMillis != null) { projectPb.setCreateTime(ISODateTimeFormat.dateTime().withZoneUTC().print(createTimeMillis)); } if (parent != null) { projectPb.setParent(parent.toPb()); } return projectPb; }
From source file:com.google.cloud.resourcemanager.testing.LocalResourceManagerHelper.java
License:Open Source License
synchronized Response create(Project project) { String customErrorMessage = checkForProjectErrors(project); if (customErrorMessage != null) { return Error.INVALID_ARGUMENT.response(customErrorMessage); } else {/*from w ww. ja va 2 s .c om*/ project.setLifecycleState("ACTIVE"); project.setProjectNumber(Math.abs(PROJECT_NUMBER_GENERATOR.nextLong() % Long.MAX_VALUE)); project.setCreateTime(ISODateTimeFormat.dateTime().print(System.currentTimeMillis())); if (projects.putIfAbsent(project.getProjectId(), project) != null) { return Error.ALREADY_EXISTS.response( "A project with the same project ID (" + project.getProjectId() + ") already exists."); } Policy emptyPolicy = new Policy().setBindings(Collections.<Binding>emptyList()) .setEtag(UUID.randomUUID().toString()).setVersion(0); policies.put(project.getProjectId(), emptyPolicy); try { String createdProjectStr = jsonFactory.toString(project); return new Response(HTTP_OK, createdProjectStr); } catch (IOException e) { return Error.INTERNAL_ERROR.response("Error serializing project " + project.getProjectId()); } } }
From source file:com.google.cloud.tools.intellij.debugger.BreakpointComparer.java
License:Apache License
@SuppressWarnings("ConstantConditions") @Override/*from w ww. ja va 2 s. com*/ public int compare(Breakpoint o1, Breakpoint o2) { if (o2.getFinalTime() == null && o1.getFinalTime() != null) { return 1; } if (o2.getFinalTime() != null && o1.getFinalTime() == null) { return -1; } if (o2.getFinalTime() == null && o1.getFinalTime() == null) { //compare file and line SourceLocation s1 = o1.getLocation(); SourceLocation s2 = o2.getLocation(); boolean s1Valid = isSourceLocationValid(s1); boolean s2Valid = isSourceLocationValid(s2); if (!s1Valid && !s2Valid) { return 0; } if (s1Valid && !s2Valid) { return -1; } if (!s1Valid && s2Valid) { return 1; } if (s1.getPath().equals(s2.getPath())) { long s1Line = toLongValue(s1.getLine().longValue()); long s2Line = toLongValue(s2.getLine().longValue()); if (s1Line > s2Line) { return 1; } if (s1Line < s2Line) { return -1; } return 0; } return s1.getPath().compareTo(s2.getPath()); } Date d1, d2; try { d1 = ISODateTimeFormat.dateTime().parseDateTime(o1.getFinalTime()).toDate(); d2 = ISODateTimeFormat.dateTime().parseDateTime(o2.getFinalTime()).toDate(); } catch (IllegalArgumentException iae) { d1 = MINIMUM_DATE; d2 = MINIMUM_DATE; } return d2.compareTo(d1); }
From source file:com.google.cloud.tools.intellij.debugger.CloudDebugProcess.java
License:Apache License
private void navigateToBreakpoint(@NotNull Breakpoint target) { Date snapshotTime;//from w w w.j a va2 s . c om try { snapshotTime = ISODateTimeFormat.dateTime().parseDateTime(target.getFinalTime()).toDate(); } catch (IllegalArgumentException iae) { snapshotTime = new Date(); } DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); currentSnapshot = target; if (!getXDebugSession().isStopped()) { getXDebugSession() .positionReached(new MySuspendContext(new CloudExecutionStack(getXDebugSession().getProject(), GctBundle.getString("clouddebug.stackat", df.format(snapshotTime)), target.getStackFrames(), target.getVariableTable(), target.getEvaluatedExpressions()))); } }
From source file:com.google.cloud.tools.intellij.debugger.ui.SnapshotsModel.java
License:Apache License
@Override public Object getValueAt(int rowIndex, int columnIndex) { if (rowIndex < 0 || rowIndex >= breakpoints.size()) { return null; }//from ww w .ja va 2s. c o m Breakpoint breakpoint = breakpoints.get(rowIndex); switch (columnIndex) { case 0: if (breakpoint.getStatus() != null && Boolean.TRUE.equals(breakpoint.getStatus().getIsError())) { return GoogleCloudToolsIcons.CLOUD_BREAKPOINT_ERROR; } if (!Boolean.TRUE.equals(breakpoint.getIsFinalState())) { return GoogleCloudToolsIcons.CLOUD_BREAKPOINT_CHECKED; } return GoogleCloudToolsIcons.CLOUD_BREAKPOINT_FINAL; case 1: if (!Boolean.TRUE.equals(breakpoint.getIsFinalState())) { return GctBundle.getString("clouddebug.pendingstatus"); } try { return ISODateTimeFormat.dateTime().parseDateTime(breakpoint.getFinalTime()).toDate(); } catch (IllegalArgumentException iae) { return new Date(); } case 2: String path = breakpoint.getLocation().getPath(); int startIndex = path.lastIndexOf('/'); return path.substring(startIndex >= 0 ? startIndex + 1 : 0) + ":" + breakpoint.getLocation().getLine().toString(); case 3: return breakpoint.getCondition(); case 4: if (snapshots.supportsMoreConfig(breakpoint)) { return GctBundle.getString("clouddebug.moreHTML"); } else { return null; } default: return null; } }
From source file:com.google.cloud.trace.sdk.CloudTraceWriter.java
License:Open Source License
/** * Helper method that pulls SDK span data into an API span. *///from www. ja v a2 s . c o m private TraceSpan convertTraceSpanDataToSpan(TraceSpanData spanData) { TraceSpan span = new TraceSpan(); span.setName(spanData.getName()); span.setParentSpanId(spanData.getParentSpanId()); span.setSpanId(spanData.getContext().getSpanId()); span.setStartTime( ISODateTimeFormat.dateTime().withZoneUTC().print(new DateTime(spanData.getStartTimeMillis()))); span.setEndTime( ISODateTimeFormat.dateTime().withZoneUTC().print(new DateTime(spanData.getEndTimeMillis()))); Map<String, String> labels = new HashMap<>(); for (Map.Entry<String, TraceSpanLabel> labelVal : spanData.getLabelMap().entrySet()) { labels.put(labelVal.getKey(), labelVal.getValue().getValue()); } span.setLabels(labels); return span; }