List of usage examples for org.joda.time DateTimeZone UTC
DateTimeZone UTC
To view the source code for org.joda.time DateTimeZone UTC.
Click Source Link
From source file:com.spectralogic.ds3cli.views.json.CommonJsonView.java
License:Open Source License
static CommonJsonView newView(final Status status) { final CommonJsonView view = new CommonJsonView(); final DateTime time = DateTime.now(DateTimeZone.UTC); return view.status(status).addMetaData("Date", time.toString(ISODateTimeFormat.dateTime())); }
From source file:com.spfsolutions.ioms.auth.UserAuthenticationProvider.java
License:Open Source License
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { try {//from w ww .j a v a2s . c o m UserEntity userEntity = userDao.queryForFirst( userDao.queryBuilder().where().eq("Username", authentication.getName()).prepare()); String inputHash = MD5.encrypt(authentication.getCredentials().toString()); if (userEntity == null || !userEntity.getPassword().equals(inputHash)) { throw new BadCredentialsException("Username or password incorrect."); } else if (!userEntity.isEnabled()) { throw new DisabledException("The username is disabled. Please contact your System Administrator."); } userEntity.setLastSuccessfulLogon(new DateTime(DateTimeZone.UTC).toDate()); userDao.createOrUpdate(userEntity); Collection<SimpleGrantedAuthority> authorities = buildRolesFromUser(userEntity); UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken( authentication.getName(), authentication.getCredentials(), authorities); return token; } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { userDao.getConnectionSource().closeQuietly(); } return null; }
From source file:com.spotify.reaper.ReaperApplication.java
License:Apache License
@Override public void run(ReaperApplicationConfiguration config, Environment environment) throws Exception { // Using UTC times everywhere as default. Affects only Yoda time. DateTimeZone.setDefault(DateTimeZone.UTC); checkConfiguration(config);//from w ww.j ava 2s . c om context.config = config; addSignalHandlers(); // SIGHUP, etc. LOG.info("initializing runner thread pool with {} threads", config.getRepairRunThreadCount()); context.repairManager = new RepairManager(); context.repairManager.initializeThreadPool(config.getRepairRunThreadCount(), config.getHangingRepairTimeoutMins(), TimeUnit.MINUTES, 30, TimeUnit.SECONDS); if (context.storage == null) { LOG.info("initializing storage of type: {}", config.getStorageType()); context.storage = initializeStorage(config, environment); } else { LOG.info("storage already given in context, not initializing a new one"); } if (context.jmxConnectionFactory == null) { LOG.info("no JMX connection factory given in context, creating default"); context.jmxConnectionFactory = new JmxConnectionFactory(); } // read jmx host/port mapping from config and provide to jmx con.factory Map<String, Integer> jmxPorts = config.getJmxPorts(); if (jmxPorts != null) { LOG.debug("using JMX ports mapping: " + jmxPorts); context.jmxConnectionFactory.setJmxPorts(jmxPorts); } // Enable cross-origin requests for using external GUI applications. if (config.isEnableCrossOrigin() || System.getProperty("enableCrossOrigin") != null) { final FilterRegistration.Dynamic cors = environment.servlets().addFilter("crossOriginRequests", CrossOriginFilter.class); cors.setInitParameter("allowedOrigins", "*"); cors.setInitParameter("allowedHeaders", "X-Requested-With,Content-Type,Accept,Origin"); cors.setInitParameter("allowedMethods", "OPTIONS,GET,PUT,POST,DELETE,HEAD"); cors.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*"); } JmxCredentials jmxAuth = config.getJmxAuth(); if (jmxAuth != null) { LOG.debug("using specified JMX credentials for authentication"); context.jmxConnectionFactory.setJmxAuth(jmxAuth); } LOG.info("creating and registering health checks"); // Notice that health checks are registered under the admin application on /healthcheck final ReaperHealthCheck healthCheck = new ReaperHealthCheck(context); environment.healthChecks().register("reaper", healthCheck); environment.jersey().register(healthCheck); LOG.info("creating resources and registering endpoints"); final PingResource pingResource = new PingResource(); environment.jersey().register(pingResource); final ClusterResource addClusterResource = new ClusterResource(context); environment.jersey().register(addClusterResource); final RepairRunResource addRepairRunResource = new RepairRunResource(context); environment.jersey().register(addRepairRunResource); final RepairScheduleResource addRepairScheduleResource = new RepairScheduleResource(context); environment.jersey().register(addRepairScheduleResource); Thread.sleep(1000); SchedulingManager.start(context); LOG.info("resuming pending repair runs"); context.repairManager.resumeRunningRepairRuns(context); }
From source file:com.springsource.greenhouse.activity.action.JdbcActionRepository.java
License:Apache License
public SimpleAction saveSimpleAction(final String type, Account account) { SimpleAction action = doSaveAction(SimpleAction.class, account, new ActionFactory<SimpleAction>() { public SimpleAction createAction(Long id, DateTime time, Account account, Location location) { return new SimpleAction(type, id, time, account, location); }/*ww w . ja v a2 s . c o m*/ }, type, Location.getCurrentLocation(), new DateTime(DateTimeZone.UTC)); actionGateway.actionPerformed(action); return action; }
From source file:com.springsource.greenhouse.activity.action.JdbcActionRepository.java
License:Apache License
public <A extends Action> A saveAction(Class<A> actionClass, Account account, ActionFactory<A> actionFactory) { A action = doSaveAction(actionClass, account, actionFactory, actionType(actionClass), Location.getCurrentLocation(), new DateTime(DateTimeZone.UTC)); actionGateway.actionPerformed(action); return action; }
From source file:com.springsource.greenhouse.activity.badge.JdbcBadgeRepository.java
License:Apache License
@Transactional public AwardedBadge createAwardedBadge(String badge, Account account, Action action) { DateTime awardTime = new DateTime(DateTimeZone.UTC); jdbcTemplate.update("insert into AwardedBadge (badge, awardTime, member, memberAction) values (?, ?, ?, ?)", badge, awardTime.toDate(), account.getId(), action.getId()); Long id = jdbcTemplate.queryForLong("call identity()"); // TODO dont hardcode String imageUrl = "http://images.greenhouse.springsource.org/activity/icon-default-badge.png"; return new AwardedBadge(id, badge, awardTime, imageUrl, account, action); }
From source file:com.springsource.greenhouse.events.JdbcEventRepository.java
License:Apache License
private static DateTime adjustEventTimeToUTC(Timestamp timestamp, String eventTimeZone) { MutableDateTime mutableDateTime = new DateTime(timestamp).toMutableDateTime(); mutableDateTime.setZoneRetainFields(DateTimeZone.forID(eventTimeZone)); DateTime utcAdjustedDateTime = mutableDateTime.toDateTime().toDateTime(DateTimeZone.UTC); return utcAdjustedDateTime; }
From source file:com.springsource.greenhouse.invite.JdbcInviteRepository.java
License:Apache License
public void markInviteAccepted(final String token, Account account) { actionRepository.saveAction(InviteAcceptAction.class, account, new ActionFactory<InviteAcceptAction>() { public InviteAcceptAction createAction(Long id, DateTime time, Account account, Location location) { jdbcTemplate.update("insert into InviteAcceptAction (invite, memberAction) values (?, ?)", token, id);/*from www.java 2s . c o m*/ Map<String, Object> invite = jdbcTemplate .queryForMap("select sentBy, sentTime from Invite where token = ?", token); Long sentBy = (Long) invite.get("sentBy"); DateTime sentTime = new DateTime(invite.get("sentTime"), DateTimeZone.UTC); return new InviteAcceptAction(id, time, account, location, sentBy, sentTime); } }); }
From source file:com.streamsets.pipeline.stage.destination.s3.AmazonS3Target.java
License:Apache License
@Override public void write(Batch batch) throws StageException { String keyPrefix = s3TargetConfigBean.s3Config.commonPrefix + s3TargetConfigBean.fileNamePrefix + "-" + new DateTime().withZone(DateTimeZone.UTC).toString("yyyyMMddHH") + "-"; Iterator<Record> records = batch.getRecords(); int writtenRecordCount = 0; DataGenerator generator;// ww w. j av a 2 s. c o m Record currentRecord; try { ByRefByteArrayOutputStream bOut = new ByRefByteArrayOutputStream(); OutputStream out = bOut; // wrap with gzip compression output stream if required if (s3TargetConfigBean.compress) { out = new GZIPOutputStream(bOut); } generator = s3TargetConfigBean.getGeneratorFactory().getGenerator(out); while (records.hasNext()) { currentRecord = records.next(); try { generator.write(currentRecord); writtenRecordCount++; } catch (IOException | StageException e) { handleException(e, currentRecord); } } generator.close(); // upload file on Amazon S3 only if at least one record was successfully written to the stream if (writtenRecordCount > 0) { fileCount++; StringBuilder fileName = new StringBuilder(); fileName = fileName.append(keyPrefix).append(fileCount); if (s3TargetConfigBean.compress) { fileName = fileName.append(GZIP_EXTENSION); } // Avoid making a copy of the internal buffer maintained by the ByteArrayOutputStream by using // ByRefByteArrayOutputStream ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bOut.getInternalBuffer(), 0, bOut.size()); PutObjectRequest putObjectRequest = new PutObjectRequest(s3TargetConfigBean.s3Config.bucket, fileName.toString(), byteArrayInputStream, null); LOG.debug("Uploading object {} into Amazon S3", s3TargetConfigBean.s3Config.bucket + s3TargetConfigBean.s3Config.delimiter + fileName); s3TargetConfigBean.s3Config.getS3Client().putObject(putObjectRequest); LOG.debug("Successfully uploaded object {} into Amazon S3", s3TargetConfigBean.s3Config.bucket + s3TargetConfigBean.s3Config.delimiter + fileName); } } catch (AmazonClientException | IOException e) { LOG.error(Errors.S3_21.getMessage(), e.toString(), e); throw new StageException(Errors.S3_21, e.toString(), e); } }
From source file:com.swap.aws.elb.client.AWSHelper.java
License:Apache License
public int getSurgeRequestCount(String loadBalancerName, String region) { int count = 0; try {/*ww w. j ava 2 s.co m*/ GetMetricStatisticsRequest request = new GetMetricStatisticsRequest(); request.setMetricName("RequestCount"); request.setNamespace("AWS/ELB"); Date currentTime = new DateTime(DateTimeZone.UTC).toDate(); Date pastTime = new DateTime(DateTimeZone.UTC).minusMinutes(120).toDate(); request.setStartTime(pastTime); request.setEndTime(currentTime); request.setPeriod(60); HashSet<String> statistics = new HashSet<String>(); statistics.add("Sum"); request.setStatistics(statistics); HashSet<Dimension> dimensions = new HashSet<Dimension>(); Dimension loadBalancerDimension = new Dimension(); loadBalancerDimension.setName("LoadBalancerName"); loadBalancerDimension.setValue("LB-1"); dimensions.add(loadBalancerDimension); request.setDimensions(dimensions); cloudWatchClient.setEndpoint(String.format("monitoring.%s.amazonaws.com", region)); // ListMetricsResult result = cloudWatchClient.listMetrics(); // // List<Metric> metrics = result.getMetrics(); // // for(Metric metric : metrics) // { // System.out.println(metric.getMetricName()); // } GetMetricStatisticsResult result = cloudWatchClient.getMetricStatistics(request); List<Datapoint> dataPoints = result.getDatapoints(); if (dataPoints != null && dataPoints.size() > 0) { count = dataPoints.get(0).getSum().intValue(); } } catch (Exception e) { e.printStackTrace(); } return count; }