Skip to content

Commit

Permalink
fix(lang): convert Groovy to Java for cloud provider classes (#4677)
Browse files Browse the repository at this point in the history
  • Loading branch information
claymccoy committed Jun 16, 2020
1 parent 48f4d34 commit 3e24caa
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 173 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Copyright 2020 Armory, Inc.
*
* 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 the License.
*
*/

package com.netflix.spinnaker.clouddriver.cache;

import com.netflix.spectator.api.Counter;
import com.netflix.spectator.api.Registry;
import com.netflix.spectator.api.Timer;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;

public class OnDemandMetricsSupport {
public static final String ON_DEMAND_TOTAL_TIME = "onDemand_total";
public static final String DATA_READ = "onDemand_read";
public static final String DATA_TRANSFORM = "onDemand_transform";
public static final String ON_DEMAND_STORE = "onDemand_store";
public static final String CACHE_WRITE = "onDemand_cache";
public static final String CACHE_EVICT = "onDemand_evict";
public static final String ON_DEMAND_ERROR = "onDemand_error";
public static final String ON_DEMAND_COUNT = "onDemand_count";

private final Timer onDemandTotal;
private final Timer dataRead;
private final Timer dataTransform;
private final Timer onDemandStore;
private final Timer cacheWrite;
private final Timer cacheEvict;
private final Counter onDemandErrors;
private final Counter onDemandCount;

public OnDemandMetricsSupport(Registry registry, OnDemandAgent agent, String onDemandType) {
final String[] tags =
new String[] {
"providerName",
agent.getProviderName(),
"agentType",
agent.getOnDemandAgentType(),
"onDemandType",
onDemandType
};
this.onDemandTotal = registry.timer(ON_DEMAND_TOTAL_TIME, tags);
this.dataRead = registry.timer(DATA_READ, tags);
this.dataTransform = registry.timer(DATA_TRANSFORM, tags);
this.onDemandStore = registry.timer(ON_DEMAND_STORE, tags);
this.cacheWrite = registry.timer(CACHE_WRITE, tags);
this.cacheEvict = registry.timer(CACHE_EVICT, tags);
this.onDemandErrors = registry.counter(ON_DEMAND_ERROR, tags);
this.onDemandCount = registry.counter(ON_DEMAND_COUNT, tags);
}

private <T> T record(Timer timer, Supplier<T> closure) {
final long start = System.nanoTime();
try {
return closure.get();
} finally {
final long elapsed = System.nanoTime() - start;
timer.record(elapsed, TimeUnit.NANOSECONDS);
}
}

public <T> T readData(Supplier<T> closure) {
return record(dataRead, closure);
}

public <T> T transformData(Supplier<T> closure) {
return record(dataTransform, closure);
}

public <T> T onDemandStore(Supplier<T> closure) {
return record(onDemandStore, closure);
}

public <T> T cacheWrite(Supplier<T> closure) {
return record(cacheWrite, closure);
}

public <T> T cacheEvict(Supplier<T> closure) {
return record(cacheEvict, closure);
}

public void countError() {
onDemandErrors.increment();
}

public void countOnDemand() {
onDemandCount.increment();
}

public void recordTotalRunTimeNanos(long nanos) {
onDemandTotal.record(nanos, TimeUnit.NANOSECONDS);
}
}
Original file line number Diff line number Diff line change
@@ -1,49 +1,51 @@
/*
* Copyright 2015 Netflix, Inc.
* Copyright 2020 Armory, Inc.
*
* 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
* 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 the License.
*
*/

package com.netflix.spinnaker.clouddriver.core
package com.netflix.spinnaker.clouddriver.core;

import java.lang.annotation.Annotation
import java.lang.annotation.Annotation;

/**
* Different cloud providers (AWS, GCE, Titus, etc.) should implement this interface and
* annotate different implementations with annotation class indicated by {@code getAnnotation} method
* to identify the cloud provider specific implementations
*
* Different cloud providers (AWS, GCE, Titus, etc.) should implement this interface and annotate
* different implementations with annotation class indicated by {@code getAnnotation} method to
* identify the cloud provider specific implementations
*/
interface CloudProvider {

public interface CloudProvider {
/**
* A unique string that identifies the cloud provider implementation
*
* @return
*/
String getId()
String getId();

/**
* Display name or simply the name for the cloud provider. Use {@code getID()} for uniqueness constraints
* instead of this method
* Display name or simply the name for the cloud provider. Use {@code getID()} for uniqueness
* constraints instead of this method
*
* @return
*/
String getDisplayName()
String getDisplayName();

/**
* Annotation type that can be assigned to the implementations for operations, converters, validators, etc. to enable
* lookup based on the operation description name and cloud provider type
* Annotation type that can be assigned to the implementations for operations, converters,
* validators, etc. to enable lookup based on the operation description name and cloud provider
* type
*
* @return
*/
Class<? extends Annotation> getOperationAnnotationType()

Class<? extends Annotation> getOperationAnnotationType();
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2020 Armory, Inc.
*
* 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 the License.
*
*/

package com.netflix.spinnaker.clouddriver.deploy;

import com.netflix.spinnaker.clouddriver.orchestration.VersionedCloudProviderOperation;
import java.util.List;
import org.springframework.validation.Errors;

public abstract class DescriptionValidator<T> implements VersionedCloudProviderOperation {
public static String getValidatorName(String description) {
return description + "Validator";
}

public abstract void validate(List priorDescriptions, T description, Errors errors);
}
Loading

0 comments on commit 3e24caa

Please sign in to comment.