use of org.wso2.carbon.apimgt.core.models.Label in project carbon-apimgt by wso2.
the class KubernetesGatewayImplTestCase method testRemoveContainerBasedGateway.
@Test
public void testRemoveContainerBasedGateway() throws Exception {
OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
KubernetesGatewayImpl kubernetesGateway = getKubernetesGatewayImpl(openShiftClient);
NonNamespaceOperation nonNamespaceOperation = Mockito.mock(NonNamespaceOperation.class);
BaseOperation baseOperation = Mockito.mock(BaseOperation.class);
Mockito.when(openShiftClient.services().inNamespace(NAMESPACE)).thenReturn(nonNamespaceOperation);
Mockito.when(nonNamespaceOperation.withLabel(Mockito.anyString(), Mockito.anyString())).thenReturn(baseOperation);
Mockito.when(baseOperation.delete()).thenReturn(true);
Mockito.when(openShiftClient.extensions().deployments().inNamespace(NAMESPACE)).thenReturn(nonNamespaceOperation);
Mockito.when(openShiftClient.extensions().ingresses().inNamespace(NAMESPACE)).thenReturn(nonNamespaceOperation);
API api = SampleTestObjectCreator.createDefaultAPI().build();
kubernetesGateway.removeContainerBasedGateway("label", api);
Mockito.verify(openShiftClient, Mockito.times(2)).services();
Mockito.verify(openShiftClient, Mockito.times(4)).extensions();
}
use of org.wso2.carbon.apimgt.core.models.Label in project carbon-apimgt by wso2.
the class GatewaysApiServiceImpl method gatewaysRegisterPost.
/**
* Register gateway
*
* @param body RegistrationDTO
* @param contentType Content-Type header value
* @return Registration summary details
* @throws NotFoundException If failed to register gateway
*/
@Override
public Response gatewaysRegisterPost(RegistrationDTO body, String contentType, Request request) throws NotFoundException {
try {
LabelInfoDTO labelInfoDTO = body.getLabelInfo();
if (labelInfoDTO != null) {
APIMgtAdminService adminService = RestApiUtil.getAPIMgtAdminService();
String overwriteLabels = labelInfoDTO.getOverwriteLabels();
List<Label> labels = MappingUtil.convertToLabels(labelInfoDTO.getLabelList());
adminService.registerGatewayLabels(labels, overwriteLabels);
RegistrationSummary registrationSummary = adminService.getRegistrationSummary();
return Response.ok().entity(MappingUtil.toRegistrationSummaryDTO(registrationSummary)).build();
} else {
String errorMessage = "Label information cannot be null";
APIMgtResourceNotFoundException e = new APIMgtResourceNotFoundException(errorMessage, ExceptionCodes.LABEL_INFORMATION_CANNOT_BE_NULL);
HashMap<String, String> paramList = new HashMap<String, String>();
org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
} catch (APIManagementException e) {
String errorMessage = "Error while registering the gateway";
HashMap<String, String> paramList = new HashMap<String, String>();
org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.core.models.Label in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisApiIdWsdlGet.
/**
* Retrieves the WSDL of the particular API. If the WSDL is added as a single file/URL, the text content of the WSDL
* will be retrived. If the WSDL is added as an archive, the binary content of the archive will be retrieved.
*
* @param apiId UUID of API
* @param labelName Name of the label
* @param ifNoneMatch If-None-Match header value
* @param ifModifiedSince If-Modified-Since header value
* @param request msf4j request
* @return WSDL archive/file content
* @throws NotFoundException
*/
@Override
public Response apisApiIdWsdlGet(String apiId, String labelName, String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
WSDLArchiveInfo wsdlArchiveInfo = null;
try {
APIStore apiStore = RestApiUtil.getConsumer(username);
String wsdlString;
if (!apiStore.isWSDLExists(apiId)) {
if (log.isDebugEnabled()) {
log.debug("WSDL has no content for API: " + apiId);
}
return Response.noContent().build();
}
if (StringUtils.isBlank(labelName)) {
if (log.isDebugEnabled()) {
log.debug("Label not provided since retrieving WSDL archive for default label. API: " + apiId);
}
labelName = APIMgtConstants.LabelConstants.DEFAULT;
}
boolean isWSDLArchiveExists = apiStore.isWSDLArchiveExists(apiId);
if (log.isDebugEnabled()) {
log.debug("API has WSDL archive?: " + isWSDLArchiveExists);
}
if (isWSDLArchiveExists) {
wsdlArchiveInfo = apiStore.getAPIWSDLArchive(apiId, labelName);
if (log.isDebugEnabled()) {
log.debug("Successfully retrieved WSDL archive for API: " + apiId);
}
// wsdlArchiveInfo will not be null all the time so no need null check
File archive = new File(wsdlArchiveInfo.getAbsoluteFilePath());
return Response.ok(archive).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM_TYPE).header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + wsdlArchiveInfo.getFileName() + "\"").build();
} else {
wsdlString = apiStore.getAPIWSDL(apiId, labelName);
if (log.isDebugEnabled()) {
log.debug("Successfully retrieved WSDL for API: " + apiId);
}
return Response.ok(wsdlString).header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN).build();
}
} catch (APIManagementException e) {
Map<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error("Error while getting WSDL for API:" + apiId + " and label:" + labelName, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
} finally {
// Commented below since MSFJ fails to reply when the files are already deleted. Need to fix this properly
/*
if (wsdlArchiveInfo != null) {
try {
APIFileUtils.deleteDirectory(wsdlArchiveInfo.getLocation());
} catch (APIMgtDAOException e) {
//This is not a blocker. Give a warning and continue
log.warn("Error occured while deleting processed WSDL artifacts folder : " + wsdlArchiveInfo
.getLocation());
}
}*/
}
}
use of org.wso2.carbon.apimgt.core.models.Label in project carbon-apimgt by wso2.
the class LabelDAOImpl method getLabelIdByNameAndType.
/**
* @see LabelDAO#getLabelIdByNameAndType(String, String)
*/
@Override
public String getLabelIdByNameAndType(String name, String type) throws APIMgtDAOException {
final String query = "SELECT LABEL_ID FROM AM_LABELS WHERE NAME = ? AND TYPE_NAME = ?";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(query)) {
statement.setString(1, name);
statement.setString(2, type);
try (ResultSet rs = statement.executeQuery()) {
if (rs.next()) {
return rs.getString("LABEL_ID");
} else {
return null;
}
}
} catch (SQLException e) {
String message = "Error while retrieving label ID of label [label Name] " + name;
throw new APIMgtDAOException(message, e, ExceptionCodes.LABEL_NOT_FOUND);
}
}
use of org.wso2.carbon.apimgt.core.models.Label in project carbon-apimgt by wso2.
the class LabelDAOImpl method deleteLabel.
/**
* @see LabelDAO#deleteLabel(String)
*/
@Override
public void deleteLabel(String labelId) throws APIMgtDAOException {
final String query = "DELETE FROM AM_LABELS WHERE LABEL_ID = ?";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(query)) {
try {
connection.setAutoCommit(false);
statement.setString(1, labelId);
statement.execute();
connection.commit();
} catch (SQLException e) {
connection.rollback();
String message = DAOUtil.DAO_ERROR_PREFIX + "deleting the label [label id] " + labelId;
throw new APIMgtDAOException(message, e);
} finally {
connection.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException e) {
String message = DAOUtil.DAO_ERROR_PREFIX + "deleting the label [label id] " + labelId;
throw new APIMgtDAOException(message, e);
}
}
Aggregations