use of io.gravitee.rest.api.model.api.ApiDeploymentEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiResourceTest method shouldDeployApi.
@Test
public void shouldDeployApi() {
ApiDeploymentEntity deployEntity = new ApiDeploymentEntity();
deployEntity.setDeploymentLabel("label");
mockApi.setState(Lifecycle.State.STARTED);
mockApi.setUpdatedAt(new Date());
doReturn(mockApi).when(apiService).deploy(any(), any(), eq(EventType.PUBLISH_API), any());
final Response response = envTarget(API + "/deploy").request().post(Entity.json(deployEntity));
assertEquals(OK_200, response.getStatus());
verify(apiService, times(1)).deploy(any(), any(), eq(EventType.PUBLISH_API), any());
}
use of io.gravitee.rest.api.model.api.ApiDeploymentEntity in project gravitee-management-rest-api by gravitee-io.
the class DynamicPropertyUpdater method update.
private void update(Collection<DynamicProperty> dynamicProperties) {
// Get latest changes
ApiEntity latestApi = apiService.findById(api.getId());
List<Property> properties = (latestApi.getProperties() != null) ? latestApi.getProperties().getProperties() : Collections.emptyList();
List<Property> userDefinedProperties = properties.stream().filter(property -> !property.isDynamic()).collect(Collectors.toList());
Map<String, Property> propertyMap = properties.stream().collect(Collectors.toMap(Property::getKey, property -> property));
List<Property> updatedProperties = new ArrayList<>();
boolean needToBeSaved = false;
for (DynamicProperty dynamicProperty : dynamicProperties) {
Property property = propertyMap.get(dynamicProperty.getKey());
if (property == null || property.isDynamic()) {
updatedProperties.add(dynamicProperty);
}
// save properties only if there's something new
if (property == null || (property.isDynamic() && !property.getValue().equals(dynamicProperty.getValue()))) {
needToBeSaved = true;
}
}
if (needToBeSaved) {
// Add previous user-defined properties
updatedProperties.addAll(userDefinedProperties);
// Sort properties alphabetically to avoid redeploy if just the order has changed.
List<Property> sortedUpdatedProperties = updatedProperties.stream().sorted(Comparator.comparing(Property::getKey)).collect(Collectors.toList());
// Create properties container
Properties apiProperties = new Properties();
try {
apiProperties.setProperties(sortedUpdatedProperties);
} catch (RuntimeException e) {
logger.error(e.getMessage(), e);
}
latestApi.setProperties(apiProperties);
boolean isSync = apiService.isSynchronized(api.getId());
// Update API
apiService.update(latestApi.getId(), ApiService.convert(latestApi));
// Do not deploy if there are manual changes to push
if (isSync) {
// Publish API only in case of changes
if (!updatedProperties.containsAll(properties) || !properties.containsAll(updatedProperties)) {
ApiDeploymentEntity deployEntity = new ApiDeploymentEntity();
deployEntity.setDeploymentLabel("Dynamic properties sync");
apiService.deploy(latestApi.getId(), "dynamic-property-updater", EventType.PUBLISH_API, deployEntity);
}
}
}
}
use of io.gravitee.rest.api.model.api.ApiDeploymentEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiResourceTest method shouldNotDeployApi.
@Test
public void shouldNotDeployApi() {
ApiDeploymentEntity deployEntity = new ApiDeploymentEntity();
deployEntity.setDeploymentLabel("label_too_long_because_more_than_32_chars");
mockApi.setState(Lifecycle.State.STARTED);
mockApi.setUpdatedAt(new Date());
doReturn(mockApi).when(apiService).deploy(any(), any(), eq(EventType.PUBLISH_API), any());
final Response response = envTarget(API + "/deploy").request().post(Entity.json(deployEntity));
assertEquals(BAD_REQUEST_400, response.getStatus());
verify(apiService, times(0)).deploy(any(), any(), eq(EventType.PUBLISH_API), any());
}
Aggregations