Allow admin users to backfill data

Ignores the usual timestamp limitations for admin users.  This will allow backfilling
data through the api, as well as migrations between dbs using the api to pull and post.

Change-Id: I72374d45421a6c53f57362c7f62db4ae6df4d6b2
This commit is contained in:
Ryan Bak 2016-11-09 14:15:34 -07:00
parent a809731d3c
commit 62ca788868
2 changed files with 12 additions and 6 deletions

View File

@ -1,11 +1,11 @@
/*
* Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
*
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
@ -121,7 +121,7 @@ public class CreateMetricCommand {
return new Metric(name, dimensions, timestamp, value, valueMeta);
}
public void validate() {
public void validate(boolean validateTimestamp) {
// Validate name and dimensions
MetricNameValidation.validate(name, true);
if (dimensions != null) {
@ -132,6 +132,8 @@ public class CreateMetricCommand {
}
// Validate times and values
validateTimestamp(timestamp);
if (validateTimestamp) {
validateTimestamp(timestamp);
}
}
}

View File

@ -92,6 +92,10 @@ public class MetricResource {
isDelegate =
!Strings.isNullOrEmpty(roles) && COMMA_SPLITTER.splitToList(roles)
.contains(monitoring_delegate_role);
boolean
isAdmin =
!Strings.isNullOrEmpty(roles) && COMMA_SPLITTER.splitToList(roles)
.contains(admin_role);
List<Metric> metrics = new ArrayList<>(commands.length);
for (CreateMetricCommand command : commands) {
if (!isDelegate) {
@ -106,8 +110,8 @@ public class MetricResource {
throw Exceptions.forbidden("Project %s cannot POST cross tenant metrics", tenantId);
}
}
command.validate(!isAdmin);
command.validate();
metrics.add(command.toMetric());
}