Skip to content

Commit

Permalink
front50 completed
Browse files Browse the repository at this point in the history
  • Loading branch information
Pranav-b-7 committed Apr 5, 2024
1 parent 632f2e4 commit 89996bc
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static java.lang.String.format;

import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerServerException;
import com.netflix.spinnaker.orca.api.pipeline.models.PipelineExecution;
import com.netflix.spinnaker.orca.api.pipeline.models.Trigger;
import com.netflix.spinnaker.orca.front50.Front50Service;
Expand All @@ -30,7 +31,6 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import retrofit.RetrofitError;

@Component
public class EnabledPipelineValidator implements PipelineValidator {
Expand Down Expand Up @@ -73,7 +73,7 @@ public void checkRunnable(PipelineExecution pipeline) {
}

return;
} catch (RetrofitError ignored) {
} catch (SpinnakerServerException ignored) {
// treat a failure to fetch pipeline config history as non-fatal and fallback to the
// previous behavior
// (handles the fast property case where the supplied pipeline config id does _not_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerHttpException;
import com.netflix.spinnaker.orca.api.pipeline.Task;
import com.netflix.spinnaker.orca.api.pipeline.TaskResult;
import com.netflix.spinnaker.orca.api.pipeline.models.StageExecution;
Expand All @@ -14,7 +15,6 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import retrofit.RetrofitError;

@Component
public class DeleteDeliveryConfigTask implements Task {
Expand Down Expand Up @@ -62,10 +62,9 @@ public Optional<DeliveryConfig> getDeliveryConfig(String id) {
try {
DeliveryConfig deliveryConfig = front50Service.getDeliveryConfig(id);
return Optional.of(deliveryConfig);
} catch (RetrofitError e) {
} catch (SpinnakerHttpException e) {
// ignore an unknown (404) or unauthorized (403, 401)
if (e.getResponse() != null
&& Arrays.asList(404, 403, 401).contains(e.getResponse().getStatus())) {
if (Arrays.asList(404, 403, 401).contains(e.getResponseCode())) {
return Optional.empty();
} else {
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerHttpException;
import com.netflix.spinnaker.orca.api.pipeline.RetryableTask;
import com.netflix.spinnaker.orca.api.pipeline.TaskResult;
import com.netflix.spinnaker.orca.api.pipeline.models.StageExecution;
Expand All @@ -36,7 +37,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import retrofit.RetrofitError;

@Component
public class MonitorFront50Task implements RetryableTask {
Expand Down Expand Up @@ -162,8 +162,8 @@ private TaskResult monitor(
private Optional<Map<String, Object>> getPipeline(String id) {
try {
return Optional.of(front50Service.getPipeline(id));
} catch (RetrofitError e) {
if (e.getResponse() != null && e.getResponse().getStatus() == HTTP_NOT_FOUND) {
} catch (SpinnakerHttpException e) {
if (e.getResponseCode() == HTTP_NOT_FOUND) {
return Optional.empty();
}
throw e;
Expand All @@ -175,10 +175,9 @@ private Optional<Map<String, Object>> getDeliveryConfig(String id) {
try {
DeliveryConfig deliveryConfig = front50Service.getDeliveryConfig(id);
return Optional.of(objectMapper.convertValue(deliveryConfig, Map.class));
} catch (RetrofitError e) {
} catch (SpinnakerHttpException e) {
// ignore an unknown (404) or unauthorized (403, 401)
if (e.getResponse() != null
&& Arrays.asList(404, 403, 401).contains(e.getResponse().getStatus())) {
if (Arrays.asList(404, 403, 401).contains(e.getResponseCode())) {
return Optional.empty();
} else {
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerHttpException;
import com.netflix.spinnaker.orca.api.pipeline.Task;
import com.netflix.spinnaker.orca.api.pipeline.TaskResult;
import com.netflix.spinnaker.orca.api.pipeline.models.ExecutionStatus;
Expand All @@ -16,7 +17,6 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import retrofit.RetrofitError;

@Component
public class UpsertDeliveryConfigTask implements Task {
Expand Down Expand Up @@ -65,9 +65,8 @@ private boolean configExists(String id) {
try {
front50Service.getDeliveryConfig(id);
return true;
} catch (RetrofitError e) {
if (e.getResponse() != null
&& Arrays.asList(404, 403, 401).contains(e.getResponse().getStatus())) {
} catch (SpinnakerHttpException e) {
if (Arrays.asList(404, 403, 401).contains(e.getResponseCode())) {
return false;
} else {
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.netflix.spinnaker.orca.front50.pipeline

import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerHttpException
import com.netflix.spinnaker.orca.front50.Front50Service
import com.netflix.spinnaker.orca.pipeline.PipelineValidator.PipelineValidationFailed
import com.netflix.spinnaker.orca.pipeline.model.DefaultTrigger
Expand Down Expand Up @@ -181,12 +182,12 @@ class EnabledPipelineValidatorSpec extends Specification {
}

def notFoundError() {
RetrofitError.httpError(
new SpinnakerHttpException(RetrofitError.httpError(
"http://localhost",
new Response("http://localhost", HTTP_NOT_FOUND, "Not Found", [], null),
null,
null
)
))
}

}
1 change: 1 addition & 0 deletions orca-pipelinetemplate/orca-pipelinetemplate.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ dependencies {
testImplementation("org.spockframework:spock-unitils")
testImplementation("org.codehaus.groovy:groovy-json")
testImplementation("io.spinnaker.fiat:fiat-core:$fiatVersion")
testImplementation("io.spinnaker.kork:kork-retrofit")
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.netflix.spinnaker.orca.pipelinetemplate.loader

import com.fasterxml.jackson.databind.ObjectMapper
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerNetworkException
import com.netflix.spinnaker.orca.front50.Front50Service
import com.netflix.spinnaker.orca.pipelinetemplate.exceptions.TemplateLoaderException
import retrofit.RetrofitError
Expand Down Expand Up @@ -47,10 +48,10 @@ class Front50SchemeLoaderSpec extends Specification {

then:
front50Service.getPipelineTemplate("myTemplateId") >> {
throw RetrofitError.networkError("http://front50/no-exist", new IOException("resource not found"))
throw new SpinnakerNetworkException(RetrofitError.networkError("http://front50/no-exist", new IOException("resource not found")))
}
def e = thrown(TemplateLoaderException)
e.cause instanceof RetrofitError
e.cause instanceof SpinnakerNetworkException
}

void 'should load simple pipeline template'() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import groovy.util.logging.Slf4j
import javassist.NotFoundException
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.*
import retrofit.RetrofitError
import retrofit.http.Query

import javax.servlet.http.HttpServletResponse
Expand Down Expand Up @@ -145,8 +144,8 @@ class OperationsController {
Map pipelineConfig = AuthenticatedRequest.allowAnonymous({ front50Service.getPipeline(pipelineConfigId) })
pipelineConfig.trigger = trigger
return pipelineConfig
} catch (RetrofitError e) {
if (e.response?.status == HTTP_NOT_FOUND) {
} catch (SpinnakerHttpException e) {
if (e.responseCode == HTTP_NOT_FOUND) {
throw new NotFoundException("Pipeline config $pipelineConfigId not found")
}
throw e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

package com.netflix.spinnaker.orca.controllers

import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerHttpException
import com.netflix.spinnaker.orca.api.pipeline.models.ExecutionStatus
import com.netflix.spinnaker.orca.api.pipeline.models.PipelineExecution
import com.netflix.spinnaker.orca.front50.Front50Service
import com.netflix.spinnaker.orca.pipeline.persistence.ExecutionRepository
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.*
import retrofit.RetrofitError
import rx.schedulers.Schedulers

@RestController
Expand All @@ -49,8 +49,8 @@ class ProjectController {
try {
def project = front50Service.getProject(projectId)
pipelineConfigIds = project.config.pipelineConfigs*.pipelineConfigId
} catch (RetrofitError e) {
if (e.response?.status == 404) {
} catch (SpinnakerHttpException e) {
if (e.responseCode == 404) {
return []
}

Expand Down

0 comments on commit 89996bc

Please sign in to comment.