Fixes from latest review.
Introduce probe interface.
ResponseWithRequestInfo is not used - it belongs to aai package and requires javax.ws.rs.core.Response.
Fallback in aai client will be removed as soon as sdc provides https support (hopefully in El Alto).
Change-Id: I4527d447a273328d38ff2ef7f9d2a93453cec9f2
Issue-ID: VID-490
Signed-off-by: Wojciech Sliwka <wojciech.sliwka@nokia.com>
}
@Override
- public ExternalComponentStatus probeAaiGetAllSubscribers(){
+ public ExternalComponentStatus probeComponent(){
long startTime = System.currentTimeMillis();
try {
AaiResponseWithRequestInfo<SubscriberList> responseWithRequestInfo = getAllSubscribers(true);
import org.onap.vid.aai.model.PortDetailsTranslator;
import org.onap.vid.aai.model.Properties;
import org.onap.vid.aai.model.ResourceType;
+import org.onap.vid.controller.ProbeInterface;
import org.onap.vid.model.SubscriberList;
-import org.onap.vid.model.probes.ExternalComponentStatus;
-
/**
* Created by Oren on 7/4/17.
*/
-public interface AaiClientInterface {
+public interface AaiClientInterface extends ProbeInterface {
boolean isNodeTypeExistsByName(String name, ResourceType type);
AaiResponse getInstanceGroupsByVnfInstanceId(String vnfInstanceId);
- ExternalComponentStatus probeAaiGetAllSubscribers();
-
Response doAaiGet(String uri, boolean xml);
String getCloudOwnerByCloudRegionId(String cloudRegionId);
}
@Override
- public ExternalComponentStatus probeGetAllSubscribers() {
+ public ExternalComponentStatus probeComponent() {
String url = urlBase + String.format(URIS.SUBSCRIBERS, 0);
long startTime = System.currentTimeMillis();
ExternalComponentStatus externalComponentStatus;
import io.joshworks.restclient.http.HttpResponse;
import org.onap.portalsdk.core.util.SystemProperties;
import org.onap.vid.aai.model.ResourceType;
+import org.onap.vid.controller.ProbeInterface;
import org.onap.vid.model.SubscriberList;
-import org.onap.vid.model.probes.ExternalComponentStatus;
-public interface AaiOverTLSClientInterface {
+public interface AaiOverTLSClientInterface extends ProbeInterface {
class URIS {
HttpResponse<SubscriberList> getAllSubscribers();
-
- ExternalComponentStatus probeGetAllSubscribers();
-
}
HttpResponse<String> checkSDCConnectivity();
+
+ String getBaseUrl();
}
return HttpResponse.fallback("");
}
+
+ @Override
+ public String getBaseUrl(){
+ return "";
+ }
+
/**
* The Class Builder.
*/
}
+ @Override
public HttpResponse<String> checkSDCConnectivity() {
String finalUrl = baseUrl + URIS.HEALTH_CHECK_ENDPOINT;
.get(finalUrl, prepareHeaders(auth, APPLICATION_JSON), Collections.emptyMap(), String.class);
}
+ @Override
+ public String getBaseUrl() {
+ return baseUrl;
+ }
+
private Map<String, String> prepareHeaders(String auth, String contentType) {
return ImmutableMap.of(
X_ECOMP_INSTANCE_ID, SystemProperties.getProperty(APP_DISPLAY_NAME),
package org.onap.vid.controller;
import org.onap.portalsdk.core.controller.RestrictedBaseController;
-import org.onap.vid.aai.AaiClient;
-import org.onap.vid.aai.AaiOverTLSClientInterface;
import org.onap.vid.model.probes.ExternalComponentStatus;
-import org.onap.vid.mso.MsoBusinessLogic;
-import org.onap.vid.scheduler.SchedulerService;
-import org.onap.vid.services.VidService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
-import java.util.ArrayList;
import java.util.List;
+import java.util.stream.Collectors;
@RestController
@RequestMapping("probe")
public class ProbeController extends RestrictedBaseController {
- private final AaiClient aaiClient;
- private final AaiOverTLSClientInterface newAaiClient;
- private final VidService vidService;
- private final MsoBusinessLogic msoBusinessLogic;
- private final SchedulerService schedulerService;
-
+ private final List<ProbeInterface> probes;
@Autowired
- public ProbeController(AaiClient aaiClient, VidService vidService, MsoBusinessLogic msoBusinessLogic, SchedulerService schedulerService, AaiOverTLSClientInterface newAaiClient) {
- this.aaiClient = aaiClient;
- this.vidService = vidService;
- this.msoBusinessLogic = msoBusinessLogic;
- this.schedulerService = schedulerService;
- this.newAaiClient = newAaiClient;
+ public ProbeController(List<ProbeInterface> probes) {
+ this.probes = probes;
}
@GetMapping
public List<ExternalComponentStatus> getProbe() {
- List<ExternalComponentStatus> componentStatuses = new ArrayList<>();
- componentStatuses.add(aaiClient.probeAaiGetAllSubscribers());
- componentStatuses.add(newAaiClient.probeGetAllSubscribers());
- componentStatuses.add(schedulerService.probeGetSchedulerChangeManagements());
- componentStatuses.add(msoBusinessLogic.probeGetOrchestrationRequests());
- componentStatuses.add(vidService.probeSDCConnection());
- return componentStatuses;
+ return probes.stream().map(ProbeInterface::probeComponent).collect(Collectors.toList());
}
-
}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2019 Nokia Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.vid.controller;
+
+import org.onap.vid.model.probes.ExternalComponentStatus;
+
+public interface ProbeInterface {
+ ExternalComponentStatus probeComponent();
+}
}
- @Bean
- public VidService vidService(AsdcClient asdcClient, FeatureManager featureManager) {
- return new VidServiceImpl(asdcClient, featureManager);
- }
-
@Bean
public SchedulerService schedulerService(ChangeManagementService changeManagementService) {
return new SchedulerServiceImpl(changeManagementService);
duration);
}
- public HttpRequestMetadata(HttpResponse<String> response, HttpMethod method, String description, long duration, String url) {
- this(method, response.getStatus(), url, response.getBody(), description, duration);
- }
-
public HttpMethod getHttpMethod() {
import org.onap.vid.changeManagement.RequestDetailsWrapper;
import org.onap.vid.changeManagement.WorkflowRequestDetail;
import org.onap.vid.controller.OperationalEnvironmentController;
+import org.onap.vid.controller.ProbeInterface;
import org.onap.vid.model.SOWorkflowList;
import org.onap.vid.model.SoftDeleteRequest;
-import org.onap.vid.model.probes.ExternalComponentStatus;
import org.onap.vid.mso.model.OperationalEnvironmentActivateInfo;
import org.onap.vid.mso.model.OperationalEnvironmentDeactivateInfo;
import org.onap.vid.mso.rest.OperationalEnvironment.OperationEnvironmentRequestDetails;
import java.util.List;
import java.util.UUID;
-public interface MsoBusinessLogic {
+public interface MsoBusinessLogic extends ProbeInterface {
// this function should get params from tosca and send them to instance at mso, then return success response.
MsoResponseWrapper createSvcInstance(RequestDetails msoRequest);
MsoResponseWrapper2 activateFabricConfiguration(String serviceInstanceId, RequestDetails requestDetails);
SOWorkflowList getWorkflowListByModelId(String modelVersionId);
-
- ExternalComponentStatus probeGetOrchestrationRequests();
}
import com.google.common.collect.ImmutableMap;
import io.joshworks.restclient.http.HttpResponse;
import org.apache.commons.collections4.ListUtils;
-import org.jetbrains.annotations.NotNull;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.portalsdk.core.util.SystemProperties;
import org.onap.vid.changeManagement.ChangeManagementRequest;
@Override
- public ExternalComponentStatus probeGetOrchestrationRequests() {
+ public ExternalComponentStatus probeComponent() {
String url = SystemProperties.getProperty(
MsoProperties.MSO_SERVER_URL) + "/" + SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQS);
long startTime = System.currentTimeMillis();
ExternalComponentStatus externalComponentStatus;
try {
- RestObject<List<Request>> restObject = createRequestsList(getOrchestrationRequestsForDashboard());
-
- StatusMetadata statusMetadata = new HttpRequestMetadata(new RestObjectWithRequestInfo(HttpMethod.GET, url, restObject),
- "VID-SO communication works", System.currentTimeMillis() - startTime);
+ String rawBody = objectMapper.writeValueAsString(getOrchestrationRequestsForDashboard());
+ StatusMetadata statusMetadata=new HttpRequestMetadata(HttpMethod.GET,200,url,rawBody,"VID-SO",System.currentTimeMillis() - startTime);
externalComponentStatus = new ExternalComponentStatus(ExternalComponentStatus.Component.MSO, true, statusMetadata);
} catch (Exception e) {
return externalComponentStatus;
}
- @NotNull
- private RestObject<List<Request>> createRequestsList(List<Request> orchestrationRequestsForDashboard) {
- RestObject<List<Request>> restObject = new RestObject<>();
- restObject.set(orchestrationRequestsForDashboard);
- restObject.setStatusCode(200);
- return restObject;
- }
-
-
private void validateUpdateVnfConfig(RequestDetails requestDetails) {
final String noValidPayloadMsg = "No valid payload in " + ChangeManagementRequest.CONFIG_UPDATE + " request";
package org.onap.vid.scheduler;
-import org.onap.vid.model.probes.ExternalComponentStatus;
+import org.onap.vid.controller.ProbeInterface;
-public interface SchedulerService {
- ExternalComponentStatus probeGetSchedulerChangeManagements();
+public interface SchedulerService extends ProbeInterface {
}
}
@Override
- public ExternalComponentStatus probeGetSchedulerChangeManagements() {
+ public ExternalComponentStatus probeComponent() {
long startTime = System.currentTimeMillis();
try {
RestObjectWithRequestInfo response = this.changeManagementService.getSchedulerChangeManagementsWithRequestInfo();
package org.onap.vid.services;
import org.onap.vid.asdc.AsdcCatalogException;
+import org.onap.vid.controller.ProbeInterface;
import org.onap.vid.model.ServiceModel;
-import org.onap.vid.model.probes.ExternalComponentStatus;
-public interface VidService {
+public interface VidService extends ProbeInterface {
ServiceModel getService(String uuid) throws AsdcCatalogException;
void invalidateServiceCache();
-
- ExternalComponentStatus probeSDCConnection();
}
* The Class VidController.
*/
+@org.springframework.stereotype.Service
public class VidServiceImpl implements VidService {
/**
* The Constant LOG.
protected final AsdcClient asdcClient;
private final FeatureManager featureManager;
- @Autowired
private ToscaParserImpl2 toscaParser;
private final LoadingCache<String, ServiceModel> serviceModelCache;
}
}
- public VidServiceImpl(AsdcClient asdcClient, FeatureManager featureManager) {
+ @Autowired
+ public VidServiceImpl(AsdcClient asdcClient, ToscaParserImpl2 toscaParser, FeatureManager featureManager) {
this.asdcClient = asdcClient;
this.featureManager = featureManager;
-
+ this.toscaParser=toscaParser;
this.serviceModelCache = CacheBuilder.newBuilder()
.maximumSize(1000)
.expireAfterAccess(7, TimeUnit.DAYS)
}
@Override
- public ExternalComponentStatus probeSDCConnection() {
+ public ExternalComponentStatus probeComponent() {
long startTime = System.currentTimeMillis();
ExternalComponentStatus externalComponentStatus;
try {
HttpResponse<String> stringHttpResponse = asdcClient.checkSDCConnectivity();
- HttpRequestMetadata httpRequestMetadata = new HttpRequestMetadata(stringHttpResponse, HttpMethod.GET, "SDC healthCheck",
- System.currentTimeMillis() - startTime, AsdcClient.URIS.HEALTH_CHECK_ENDPOINT);
+ HttpRequestMetadata httpRequestMetadata = new HttpRequestMetadata(HttpMethod.GET, stringHttpResponse.getStatus(), asdcClient.getBaseUrl() + AsdcClient.URIS.HEALTH_CHECK_ENDPOINT, stringHttpResponse.getBody(), "SDC healthCheck",
+ System.currentTimeMillis() - startTime);
externalComponentStatus = new ExternalComponentStatus(ExternalComponentStatus.Component.SDC, stringHttpResponse.isSuccessful(), httpRequestMetadata);
} catch (Exception e) {
HttpRequestMetadata httpRequestMetadata = new HttpRequestMetadata(HttpMethod.GET, 0,
new AaiResponseWithRequestInfo<>(
HttpMethod.GET, "url", new AaiResponse<>(subscribers, null, 200),
"rawData"));
- Mockito.when(aaiClientMock.probeAaiGetAllSubscribers()).thenCallRealMethod();
- ExternalComponentStatus result = aaiClientMock.probeAaiGetAllSubscribers();
+ Mockito.when(aaiClientMock.probeComponent()).thenCallRealMethod();
+ ExternalComponentStatus result = aaiClientMock.probeComponent();
assertThat(statusDataReflected(result),is(statusDataReflected(expectedStatus)));
assertThat(requestMetadataReflected(result.getMetadata()),is(requestMetadataReflected(expectedStatus.getMetadata())));
}
}
private ExternalComponentStatus callProbeAaiGetAllSubscribersAndAssertNotAvailable() {
- Mockito.when(aaiClientMock.probeAaiGetAllSubscribers()).thenCallRealMethod();
- ExternalComponentStatus result = aaiClientMock.probeAaiGetAllSubscribers();
+ Mockito.when(aaiClientMock.probeComponent()).thenCallRealMethod();
+ ExternalComponentStatus result = aaiClientMock.probeComponent();
assertFalse(result.isAvailable());
return result;
}
when(response.isSuccessful()).thenReturn(true);
- ExternalComponentStatus externalComponentStatus = aaiRestClient.probeGetAllSubscribers();
+ ExternalComponentStatus externalComponentStatus = aaiRestClient.probeComponent();
assertThat(externalComponentStatus.isAvailable()).isTrue();
assertThat(externalComponentStatus.getComponent()).isEqualTo(ExternalComponentStatus.Component.AAI);
when(syncRestClient.get(contains(SUBSCRIBERS), eq(getHeaders()), eq(Collections.emptyMap()),
eq(SubscriberList.class))).thenThrow(new RuntimeException("call failed"));
- ExternalComponentStatus externalComponentStatus = aaiRestClient.probeGetAllSubscribers();
+ ExternalComponentStatus externalComponentStatus = aaiRestClient.probeComponent();
assertThat(externalComponentStatus.isAvailable()).isFalse();
assertThat(externalComponentStatus.getComponent()).isEqualTo(ExternalComponentStatus.Component.AAI);
@Bean
- public VidService vidService(AsdcClient asdcClient, FeatureManager featureManager) {
- return new VidServiceImpl(asdcClient, featureManager);
+ public VidService vidService(AsdcClient asdcClient, ToscaParserImpl2 toscaParserImpl2,FeatureManager featureManager) {
+ return new VidServiceImpl(asdcClient,toscaParserImpl2, featureManager);
}
@Bean
given(msoInterface.getOrchestrationRequest(anyString(),anyString(),
anyString(),any(RestObject.class),anyBoolean())).willReturn(wrapper);
- ExternalComponentStatus externalComponentStatus = msoBusinessLogic.probeGetOrchestrationRequests();
+ ExternalComponentStatus externalComponentStatus = msoBusinessLogic.probeComponent();
assertThat(externalComponentStatus.isAvailable()).isTrue();
assertThat(externalComponentStatus.getComponent()).isEqualTo(ExternalComponentStatus.Component.MSO);
restObjectWithRequestInfo
);
- final ExternalComponentStatus schedulerStatus = schedulerService.probeGetSchedulerChangeManagements();
+ final ExternalComponentStatus schedulerStatus = schedulerService.probeComponent();
assertSchedulerStatus(schedulerStatus, true);
assertMetadata(schedulerStatus, 200, startsWith(responseString.substring(0, 400)), "my pretty url", equalTo("OK"));
restObjectWithRequestInfo
);
- final ExternalComponentStatus schedulerStatus = schedulerService.probeGetSchedulerChangeManagements();
+ final ExternalComponentStatus schedulerStatus = schedulerService.probeComponent();
assertSchedulerStatus(schedulerStatus, true);
when(changeManagementService.getSchedulerChangeManagementsWithRequestInfo()).thenThrow(new ExceptionWithRequestInfo(HttpMethod.GET,
"my pretty url", responseString, 200, new JsonParseException(null, "Unrecognized token")));
- final ExternalComponentStatus schedulerStatus = schedulerService.probeGetSchedulerChangeManagements();
+ final ExternalComponentStatus schedulerStatus = schedulerService.probeComponent();
assertSchedulerStatus(schedulerStatus, false);
when(changeManagementService.getSchedulerChangeManagementsWithRequestInfo()).thenThrow(
new GenericUncheckedException(new NotFoundException("Get with status = 400")));
- final ExternalComponentStatus schedulerStatus = schedulerService.probeGetSchedulerChangeManagements();
+ final ExternalComponentStatus schedulerStatus = schedulerService.probeComponent();
assertThat(schedulerStatus.isAvailable(), is(false));
assertThat(schedulerStatus.getComponent(), is(SCHEDULER));
public void initMocks() throws AsdcCatalogException, SdcToscaParserException, IllegalAccessException {
MockitoAnnotations.initMocks(this);
- vidService = new VidServiceImpl(asdcClientMock, featureManager);
+ vidService = new VidServiceImpl(asdcClientMock, toscaParserMock, featureManager);
FieldUtils.writeField(vidService, "toscaParser", toscaParserMock, true);
when(featureManager.isActive(Features.FLAG_SERVICE_MODEL_CACHE)).thenReturn(true);
when(httpResponse.getBody()).thenReturn("sampleBody");
- ExternalComponentStatus externalComponentStatus = vidService.probeSDCConnection();
+ ExternalComponentStatus externalComponentStatus = vidService.probeComponent();
assertThat(externalComponentStatus.isAvailable(), is(true));
assertThat(externalComponentStatus.getComponent(), is(ExternalComponentStatus.Component.SDC));
public void shouldProperlyHandleNotWorkingSDCConnection(){
when(asdcClientMock.checkSDCConnectivity()).thenThrow(new RuntimeException("not working"));
- ExternalComponentStatus externalComponentStatus = vidService.probeSDCConnection();
+ ExternalComponentStatus externalComponentStatus = vidService.probeComponent();
assertThat(externalComponentStatus.isAvailable(), is(false));
assertThat(externalComponentStatus.getMetadata().getDescription(),containsString("not working"));