Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OP-20548 : Added new controller for SSD service #378

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docker_build/gate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ services:
auditclient:
baseUrl: http://localhost:8098
enabled: true
ssdservice:
baseUrl: http://localhost:8099
enabled: true
oesui:
externalUrl: http://150.238.22.102

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,12 @@ class GateConfig extends RedisHttpSessionConfiguration {
createClient "auditservice", OpsmxAuditService, okHttpClient
}

@Bean
@ConditionalOnProperty("services.ssdservice.enabled")
OpsmxSsdService ops(OkHttpClient okHttpClient) {
createClient "ssdservice", OpsmxSsdService, okHttpClient
}

@Bean
@ConditionalOnProperty("services.keel.enabled")
KeelService keelService(OkHttpClientProvider clientProvider, OkHttpClient okHttpClient) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
/*
* Copyright 2023 OpsMx, 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.gate.controllers

import com.netflix.spinnaker.gate.services.internal.OpsmxSsdService
import groovy.util.logging.Slf4j
import io.swagger.annotations.ApiOperation
import org.apache.commons.io.IOUtils
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression
import org.springframework.http.HttpHeaders
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import retrofit.client.Response

import java.util.stream.Collectors

@RequestMapping("/ssdservice")
@RestController
@Slf4j
@ConditionalOnExpression('${services.ssdservice.enabled:false}')
class OpsmxSsdController {

@Autowired
OpsmxSsdService opsMxSsdService

@ApiOperation(value = "Endpoint for ssd services")
@RequestMapping(value = "/{version}/{type}", method = RequestMethod.GET)
Object getSsdResponse(@PathVariable("version") String version,
@PathVariable("type") String type,
@RequestParam(value = "appId", required = false) Integer appId,
@RequestParam(value = "image", required = false) String image,
@RequestParam(value = "appName", required = false) String appName) {
return opsMxSsdService.getSddResponse1(version, type, appId, image, appName)
}

@ApiOperation(value = "Endpoint for ssd services")
@RequestMapping(value = "/{version}/{type}/{source}", method = RequestMethod.GET)
Object getSsdResponse1(@PathVariable("version") String version,
@PathVariable("type") String type,
@PathVariable("source") String source,
@RequestParam(value = "appId", required = false) Integer appId,
@RequestParam(value = "image", required = false) String image,
@RequestParam(value = "appName", required = false) String appName) {
return opsMxSsdService.getSddResponse2(version, type, source, appId, image, appName)
}

@ApiOperation(value = "Endpoint for ssd services")
@RequestMapping(value = "/{version}/{type}/{source}/{source1}", method = RequestMethod.GET)
Object getSsdResponse2(@PathVariable("version") String version,
@PathVariable("type") String type,
@PathVariable("source") String source,
@PathVariable("source1") String source1,
@RequestParam(value = "appId", required = false) Integer appId,
@RequestParam(value = "image", required = false) String image,
@RequestParam(value = "appName", required = false) String appName) {
return opsMxSsdService.getSddResponse3(version, type, source, source1, appId, image, appName)
}

@ApiOperation(value = "Endpoint for ssd services")
@RequestMapping(value = "/{version}/{type}/{source}/{source1}/{source2}", method = RequestMethod.GET)
Object getSsdResponse3(@PathVariable("version") String version,
@PathVariable("type") String type,
@PathVariable("source") String source,
@PathVariable("source1") String source1,
@PathVariable("source2") String source2,
@RequestParam(value = "appId", required = false) Integer appId,
@RequestParam(value = "image", required = false) String image,
@RequestParam(value = "appName", required = false) String appName) {
return opsMxSsdService.getSddResponse4(version, type, source, source1, source2, appId, image, appName)
}

@ApiOperation(value = "Endpoint for ssd services")
@RequestMapping(value = "/{version}/{type}/{source}/{source1}/{source2}/{source3}", method = RequestMethod.GET)
Object getSsdResponse4(@PathVariable("version") String version,
@PathVariable("type") String type,
@PathVariable("source") String source,
@PathVariable("source1") String source1,
@PathVariable("source2") String source2,
@PathVariable("source3") String source3,
@RequestParam(value = "appId", required = false) Integer appId,
@RequestParam(value = "image", required = false) String image,
@RequestParam(value = "appName", required = false) String appName) {
return opsMxSsdService.getSddResponse5(version, type, source, source1, source2, source3, appId, image, appName)
}

@ApiOperation(value = "Endpoint for ssd services")
@RequestMapping(value = "/{version}/{type}/{source}/{source1}/{source2}/{source3}/{source4}", method = RequestMethod.GET)
Object getSsdResponse5(@PathVariable("version") String version,
@PathVariable("type") String type,
@PathVariable("source") String source,
@PathVariable("source1") String source1,
@PathVariable("source2") String source2,
@PathVariable("source3") String source3,
@PathVariable("source4") String source4,
@RequestParam(value = "appId", required = false) Integer appId,
@RequestParam(value = "image", required = false) String image,
@RequestParam(value = "appName", required = false) String appName) {
return opsMxSsdService.getSddResponse6(version, type, source, source1, source2, source3, source4, appId, image, appName)
}

@ApiOperation(value = "Endpoint for ssd services")
@RequestMapping(value = "/{version}/{type}/{source}/{source1}/{source2}/{source3}/{source4}/{source5}", method = RequestMethod.GET)
Object getSsdResponse6(@PathVariable("version") String version,
@PathVariable("type") String type,
@PathVariable("source") String source,
@PathVariable("source1") String source1,
@PathVariable("source2") String source2,
@PathVariable("source3") String source3,
@PathVariable("source4") String source4,
@PathVariable("source5") String source5,
@RequestParam(value = "appId", required = false) Integer appId,
@RequestParam(value = "image", required = false) String image,
@RequestParam(value = "appName", required = false) String appName) {
return opsMxSsdService.getSddResponse7(version, type, source, source1, source2, source3, source4, source5, appId, image, appName)
}

@ApiOperation(value = "Endpoint to download csv file")
@RequestMapping(value = "/{version}/{type}/{source}/download", produces = "text/csv", method = RequestMethod.GET)
Object downloadCSVFileAuditService(@PathVariable("version") String version,
@PathVariable("type") String type,
@PathVariable("source") String source,
@RequestParam(value = "appId", required = false) Integer appId,
@RequestParam(value = "image", required = false) String image,
@RequestParam(value = "appName", required = false) String appName) {
Response response = opsMxSsdService.downloadCSVFile(version, type, source, appId, image, appName)
log.info("response for the download csv endpoint:" + response.getHeaders())
if (response.getBody() != null) {
InputStream inputStream = response.getBody().in()
try {
byte[] csvFile = IOUtils.toByteArray(inputStream)
HttpHeaders headers = new HttpHeaders()
headers.setContentType(MediaType.parseMediaType("text/csv"));
headers.add("Content-Disposition", response.getHeaders().stream().filter({ header -> header.getName().trim().equalsIgnoreCase("Content-Disposition") }).collect(Collectors.toList()).get(0).value)
return ResponseEntity.ok().headers(headers).body(csvFile)
} finally {
if (inputStream != null) {
inputStream.close()
}
}
}
return ResponseEntity.status(response.getStatus()).build()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* Copyright 2023 OpsMx, 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.gate.services.internal

import retrofit.client.Response
import retrofit.http.GET
import retrofit.http.Path
import retrofit.http.Query

interface OpsmxSsdService {

@GET("/ssdservice/{version}/{type}")
Object getSddResponse1(@Path('version') String version,
@Path('type') String type,
@Query("appId") Integer appId,
@Query("image") String image,
@Query("appName") String appName)

@GET("/ssdservice/{version}/{type}/{source}")
Object getSddResponse2(@Path('version') String version,
@Path('type') String type,
@Path('source') String source,
@Query("appId") Integer appId,
@Query("image") String image,
@Query("appName") String appName)

@GET("/ssdservice/{version}/{type}/{source}/{source1}")
Object getSddResponse3(@Path('version') String version,
@Path('type') String type,
@Path('source') String source,
@Path('source1') String source1,
@Query("appId") Integer appId,
@Query("image") String image,
@Query("appName") String appName)

@GET("/ssdservice/{version}/{type}/{source}/{source1}/{source2}")
Object getSddResponse4(@Path('version') String version,
@Path('type') String type,
@Path('source') String source,
@Path('source1') String source1,
@Path('source2') String source2,
@Query("appId") Integer appId,
@Query("image") String image,
@Query("appName") String appName)

@GET("/ssdservice/{version}/{type}/{source}/{source1}/{source2}/{source3}")
Object getSddResponse5(@Path('version') String version,
@Path('type') String type,
@Path('source') String source,
@Path('source1') String source1,
@Path('source2') String source2,
@Path('source3') String source3,
@Query("appId") Integer appId,
@Query("image") String image,
@Query("appName") String appName)

@GET("/ssdservice/{version}/{type}/{source}/{source1}/{source2}/{source3}/{source4}")
Object getSddResponse6(@Path('version') String version,
@Path('type') String type,
@Path('source') String source,
@Path('source1') String source1,
@Path('source2') String source2,
@Path('source3') String source3,
@Path('source4') String source4,
@Query("appId") Integer appId,
@Query("image") String image,
@Query("appName") String appName)

@GET("/ssdservice/{version}/{type}/{source}/{source1}/{source2}/{source3}/{source4}/{source5}")
Object getSddResponse7(@Path('version') String version,
@Path('type') String type,
@Path('source') String source,
@Path('source1') String source1,
@Path('source2') String source2,
@Path('source3') String source3,
@Path('source4') String source4,
@Path('source5') String source5,
@Query("appId") Integer appId,
@Query("image") String image,
@Query("appName") String appName)

@GET("/ssdservice/{version}/{type}/{source}/download")
Response downloadCSVFile(@Path('version') String version,
@Path('type') String type,
@Path('source') String source,
@Query("appId") Integer appId,
@Query("image") String image,
@Query("appName") String appName)

}