use of org.wso2.carbon.apimgt.api.model.Label in project carbon-apimgt by wso2.
the class KubernetesGatewayImpl method createContainerGateway.
/**
* @see ContainerBasedGatewayGenerator#createContainerGateway(String, API)
*/
@Override
public void createContainerGateway(String label, API api) throws ContainerBasedGatewayException {
Map<String, String> templateValues = new HashMap<>();
String serviceName = label + ContainerBasedGatewayConstants.CMS_SERVICE_SUFFIX;
String deploymentName = label + ContainerBasedGatewayConstants.CMS_DEPLOYMENT_SUFFIX;
String ingressName = label + ContainerBasedGatewayConstants.CMS_INGRESS_SUFFIX;
templateValues.put(ContainerBasedGatewayConstants.NAMESPACE, namespace);
templateValues.put(ContainerBasedGatewayConstants.GATEWAY_LABEL, label);
templateValues.put(ContainerBasedGatewayConstants.SERVICE_NAME, serviceName);
templateValues.put(ContainerBasedGatewayConstants.DEPLOYMENT_NAME, deploymentName);
templateValues.put(ContainerBasedGatewayConstants.INGRESS_NAME, ingressName);
templateValues.put(ContainerBasedGatewayConstants.CONTAINER_NAME, label + ContainerBasedGatewayConstants.CMS_CONTAINER_SUFFIX);
templateValues.put(ContainerBasedGatewayConstants.API_CORE_URL, apiCoreUrl);
templateValues.put(ContainerBasedGatewayConstants.BROKER_HOST, brokerHost);
templateValues.put(ContainerBasedGatewayConstants.GATEWAY_HOSTNAME, generateSubDomain(api) + "." + gatewayHostname);
ContainerBasedGatewayTemplateBuilder builder = new ContainerBasedGatewayTemplateBuilder();
// Create gateway service resource
createServiceResource(builder.generateTemplate(templateValues, ContainerBasedGatewayConstants.GATEWAY_SERVICE_TEMPLATE), serviceName);
// Create gateway deployment resource
createDeploymentResource(builder.generateTemplate(templateValues, ContainerBasedGatewayConstants.GATEWAY_DEPLOYMENT_TEMPLATE), deploymentName);
// Create gateway ingress resource
createIngressResource(builder.generateTemplate(templateValues, ContainerBasedGatewayConstants.GATEWAY_INGRESS_TEMPLATE), ingressName);
}
use of org.wso2.carbon.apimgt.api.model.Label in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testUpdateGetDedicatedGateway.
@Test
public void testUpdateGetDedicatedGateway() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI().apiDefinition(SampleTestObjectCreator.apiDefinition);
API api = builder.build();
testAddGetEndpoint();
apiDAO.addAPI(api);
String autoGeneratedLabelName = ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + api.getId();
List<Label> labelList = new ArrayList<>();
LabelDAO labelDAO = DAOFactory.getLabelDAO();
Label autoGenLabel = new Label.Builder().id(UUID.randomUUID().toString()).name(autoGeneratedLabelName).accessUrls(null).build();
labelList.add(autoGenLabel);
labelDAO.addLabels(labelList);
DedicatedGateway dedicatedGateway = new DedicatedGateway();
dedicatedGateway.setEnabled(true);
dedicatedGateway.setUpdatedBy(api.getCreatedBy());
dedicatedGateway.setApiId(api.getId());
List<String> labels = new ArrayList<>();
labels.add(autoGeneratedLabelName);
apiDAO.updateDedicatedGateway(dedicatedGateway, labels);
DedicatedGateway result = apiDAO.getDedicatedGateway(api.getId());
Assert.assertEquals(result.isEnabled(), dedicatedGateway.isEnabled());
}
use of org.wso2.carbon.apimgt.api.model.Label in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testAddAPIWithoutAddingLabels.
@Test
public void testAddAPIWithoutAddingLabels() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
Label label1 = SampleTestObjectCreator.createLabel("public", SampleTestObjectCreator.LABEL_TYPE_STORE).build();
Label label2 = SampleTestObjectCreator.createLabel("private", SampleTestObjectCreator.LABEL_TYPE_STORE).build();
List<String> labelIds = new ArrayList<>();
labelIds.add(label1.getId());
labelIds.add(label2.getId());
API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI();
API api = builder.build();
testAddGetEndpoint();
apiDAO.addAPI(api);
API apiFromDB = apiDAO.getAPI(api.getId());
Assert.assertNotNull(apiFromDB);
Assert.assertEquals(apiFromDB.getLabels().size(), 2);
}
use of org.wso2.carbon.apimgt.api.model.Label in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testGetAPIsByStatusAndLabel.
@Test
public void testGetAPIsByStatusAndLabel() throws Exception {
// Define statuses used in test
final String publishedStatus = "PUBLISHED";
final String createdStatus = "CREATED";
// Define labels used in test
final String publicLabel = "public";
final String privateLabel = "private";
// Add labels
LabelDAO labelDAO = DAOFactory.getLabelDAO();
Label label1 = SampleTestObjectCreator.createLabel(publicLabel, SampleTestObjectCreator.LABEL_TYPE_GATEWAY).build();
Label label2 = SampleTestObjectCreator.createLabel(privateLabel, SampleTestObjectCreator.LABEL_TYPE_GATEWAY).build();
List<Label> labelList = new ArrayList<>();
labelList.add(label1);
labelList.add(label2);
LabelDAOImpl.addLabel(label1);
LabelDAOImpl.addLabel(label2);
String publicLabelId = labelDAO.getLabelIdByNameAndType(publicLabel, SampleTestObjectCreator.LABEL_TYPE_GATEWAY);
String privateLabelId = labelDAO.getLabelIdByNameAndType(privateLabel, SampleTestObjectCreator.LABEL_TYPE_GATEWAY);
ApiDAO apiDAO = DAOFactory.getApiDAO();
// Define number of APIs to be created for a given status
final int numberOfPublishedWithLabelPublicPrivate = 1;
final int numberOfPublishedWithLabelPrivate = 2;
final int numberOfCreatedWithLabelPublic = 3;
// Add APIs with Status = PUBLISHED having labels "public" and "private"
List<API> publishedAPIsPublicPrivateSummary = new ArrayList<>();
List<String> labelsPublicPrivate = new ArrayList<>(Arrays.asList(publicLabelId, privateLabelId));
testAddGetEndpoint();
for (int i = 0; i < numberOfPublishedWithLabelPublicPrivate; ++i) {
API api = SampleTestObjectCreator.createUniqueAPI().lifeCycleStatus(publishedStatus).labels(labelsPublicPrivate).build();
publishedAPIsPublicPrivateSummary.add(SampleTestObjectCreator.getSummaryFromAPI(api));
apiDAO.addAPI(api);
}
// Add APIs with Status = PUBLISHED having label "private"
List<API> publishedAPIsPrivateSummary = new ArrayList<>();
List<String> labelsPrivate = new ArrayList<>(Collections.singletonList(privateLabelId));
for (int i = 0; i < numberOfPublishedWithLabelPrivate; ++i) {
API api = SampleTestObjectCreator.createUniqueAPI().lifeCycleStatus(publishedStatus).labels(labelsPrivate).build();
publishedAPIsPrivateSummary.add(SampleTestObjectCreator.getSummaryFromAPI(api));
apiDAO.addAPI(api);
}
// Add APIs with Status = CREATED having labels "public"
List<API> createdAPIsPublicSummary = new ArrayList<>();
List<String> labelsPublic = new ArrayList<>(Collections.singletonList(publicLabelId));
for (int i = 0; i < numberOfCreatedWithLabelPublic; ++i) {
API api = SampleTestObjectCreator.createUniqueAPI().lifeCycleStatus(createdStatus).labels(labelsPublic).build();
createdAPIsPublicSummary.add(SampleTestObjectCreator.getSummaryFromAPI(api));
apiDAO.addAPI(api);
}
// verifying APIs with Status = PUBLISHED having labels "public" or "private"
List<API> publishedPublicPrivateApiListFromDB = apiDAO.getAPIsByStatus(Arrays.asList(publicLabel, privateLabel), publishedStatus);
List<API> publishedApisWithPublicOrPrivateLabels = new ArrayList<>();
publishedApisWithPublicOrPrivateLabels.addAll(publishedAPIsPrivateSummary);
publishedApisWithPublicOrPrivateLabels.addAll(publishedAPIsPublicPrivateSummary);
Assert.assertTrue(APIUtils.isListsEqualIgnoreOrder(publishedPublicPrivateApiListFromDB, publishedApisWithPublicOrPrivateLabels, new APIComparator()));
List<API> publishedApisWithPrivateLabels = new ArrayList<>();
publishedApisWithPrivateLabels.addAll(publishedAPIsPrivateSummary);
publishedApisWithPrivateLabels.addAll(publishedAPIsPublicPrivateSummary);
// verifying APIs with Status = PUBLISHED having label "private"
List<API> publishedPrivateApiListFromDB = apiDAO.getAPIsByStatus(Collections.singletonList(privateLabel), publishedStatus);
Assert.assertTrue(APIUtils.isListsEqualIgnoreOrder(publishedPrivateApiListFromDB, publishedApisWithPrivateLabels, new APIComparator()));
// verifying APIs with Status = CREATED having label "public"
List<API> createdPublicApiListFromDB = apiDAO.getAPIsByStatus(Collections.singletonList(publicLabel), createdStatus);
Assert.assertTrue(APIUtils.isListsEqualIgnoreOrder(createdPublicApiListFromDB, createdAPIsPublicSummary, new APIComparator()));
// verifying APIs with Status = CREATED having label "private"
List<API> createdPrivateApiListFromDB = apiDAO.getAPIsByStatus(Collections.singletonList(privateLabel), createdStatus);
Assert.assertTrue(createdPrivateApiListFromDB.isEmpty());
}
use of org.wso2.carbon.apimgt.api.model.Label in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testUpdateAPIWithLabels.
@Test
public void testUpdateAPIWithLabels() throws Exception {
LabelDAO labelDAO = DAOFactory.getLabelDAO();
Label label1 = SampleTestObjectCreator.createLabel("public", SampleTestObjectCreator.LABEL_TYPE_STORE).build();
Label label2 = SampleTestObjectCreator.createLabel("private", SampleTestObjectCreator.LABEL_TYPE_STORE).build();
LabelDAOImpl.addLabel(label1);
LabelDAOImpl.addLabel(label2);
ApiDAO apiDAO = DAOFactory.getApiDAO();
List<String> labelIds = new ArrayList<>();
labelIds.add(label1.getId());
API.APIBuilder builder1 = SampleTestObjectCreator.createDefaultAPI();
API api = builder1.labels(labelIds).build();
testAddGetEndpoint();
apiDAO.addAPI(api);
API apiFromDBWithOneLabel = apiDAO.getAPI(api.getId());
Assert.assertEquals(apiFromDBWithOneLabel.getLabels().size(), builder1.getLabels().size());
labelIds.add(label2.getId());
API substituteAPI = new API.APIBuilder(api).labels(labelIds).build();
apiDAO.updateAPI(api.getId(), substituteAPI);
API apiFromDB = apiDAO.getAPI(api.getId());
API expectedAPI = SampleTestObjectCreator.copyAPIIgnoringNonEditableFields(api, substituteAPI);
Assert.assertNotNull(apiFromDB);
Assert.assertEquals(apiFromDB.getLabels().size(), expectedAPI.getLabels().size());
}
Aggregations