use of org.apache.commons.lang3.StringUtils.isEmpty in project halyard by spinnaker.
the class DeploymentConfigurationValidator method validate.
@Override
public void validate(ConfigProblemSetBuilder p, DeploymentConfiguration n) {
String timezone = n.getTimezone();
if (Arrays.stream(TimeZone.getAvailableIDs()).noneMatch(t -> t.equals(timezone))) {
p.addProblem(Problem.Severity.ERROR, "Timezone " + timezone + " does not match any known canonical timezone ID").setRemediation("Pick a timezone from those listed here: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones");
}
String version = n.getVersion();
Versions versions = versionsService.getVersions();
boolean localGit = n.getDeploymentEnvironment().getType() == DeploymentType.LocalGit;
if (StringUtils.isEmpty(version)) {
p.addProblem(Problem.Severity.WARNING, "You have not yet selected a version of Spinnaker to deploy.", "version");
return;
}
Optional<Versions.IllegalVersion> illegalVersion = versions.getIllegalVersions().stream().filter(v -> v.getVersion().equals(version)).findAny();
if (illegalVersion.isPresent()) {
p.addProblem(Problem.Severity.ERROR, "Version \"" + version + "\" may no longer be deployed with Halyard: " + illegalVersion.get().getReason());
return;
}
if (Versions.isBranch(version) && !localGit) {
p.addProblem(Problem.Severity.FATAL, "You can't run Spinnaker from a branch when your deployment type isn't \"LocalGit\".").setRemediation("Either pick a version (hal version list) or set a different deployment type (hal config deploy edit --type <t>).");
return;
}
try {
if (!Versions.isBranch(version)) {
versionsService.getBillOfMaterials(version);
}
} catch (HalException e) {
if (localGit) {
p.addProblem(Problem.Severity.FATAL, "Could not fetch your desired version.").setRemediation("Is it possible that you're trying to checkout a branch? Prefix the version with \"" + Versions.BRANCH_PREFIX + "\".");
return;
}
p.extend(e);
return;
} catch (Exception e) {
p.addProblem(Problem.Severity.FATAL, "Unexpected error trying to validate version \"" + version + "\": " + e.getMessage(), "version");
return;
}
Optional<Versions.Version> releasedVersion = versions.getVersions().stream().filter(v -> Objects.equals(v.getVersion(), version)).findFirst();
boolean isReleased = releasedVersion.isPresent();
String runningVersion = versionsService.getRunningHalyardVersion();
boolean halyardSnapshotRelease = runningVersion.endsWith("SNAPSHOT");
if (isReleased && !localGit) {
String minimumHalyardVersion = releasedVersion.get().getMinimumHalyardVersion();
if (!halyardSnapshotRelease && !StringUtils.isEmpty(minimumHalyardVersion) && Versions.lessThan(runningVersion, minimumHalyardVersion)) {
p.addProblem(Problem.Severity.ERROR, "Halyard version \"" + runningVersion + "\" is less than Halyard version \"" + minimumHalyardVersion + "\" required for Spinnaker \"" + version + "\"");
}
} else {
// Checks if version is of the form X.Y.Z
if (version.matches("\\d+\\.\\d+\\.\\d+")) {
String majorMinor = Versions.toMajorMinor(version);
Optional<Versions.Version> patchVersion = versions.getVersions().stream().map(v -> new ImmutablePair<>(v, Versions.toMajorMinor(v.getVersion()))).filter(v -> v.getRight() != null).filter(v -> v.getRight().equals(majorMinor)).map(ImmutablePair::getLeft).findFirst();
if (patchVersion.isPresent()) {
p.addProblem(Problem.Severity.WARNING, "Version \"" + version + "\" was patched by \"" + patchVersion.get().getVersion() + "\". Please upgrade when possible.").setRemediation("https://spinnaker.io/setup/install/upgrades/");
} else {
p.addProblem(Problem.Severity.WARNING, "Version \"" + version + "\" is no longer supported by the Spinnaker team. Please upgrade when possible.").setRemediation("https://spinnaker.io/setup/install/upgrades/");
}
} else {
p.addProblem(Problem.Severity.WARNING, "Version \"" + version + "\" is not a released (validated) version of Spinnaker.", "version");
}
}
}
use of org.apache.commons.lang3.StringUtils.isEmpty in project photon-model by vmware.
the class AzureStorageEnumerationAdapterService method updateStorageDescriptions.
/**
* Updates matching storage descriptions for given storage accounts.
*/
private void updateStorageDescriptions(StorageEnumContext context, StorageEnumStages next) {
if (context.storageDescriptions.size() == 0) {
logFine(() -> "No storage descriptions available for update");
context.subStage = next;
handleSubStage(context);
return;
}
List<DeferredResult<Operation>> updates = context.storageDescriptions.values().stream().map(sd -> {
StorageAccount storageAccount = context.storageAccountsToUpdateCreate.remove(sd.id);
StorageDescription storageDescriptionToUpdate = new StorageDescription();
storageDescriptionToUpdate.name = storageAccount.name;
storageDescriptionToUpdate.authCredentialsLink = sd.authCredentialsLink;
storageDescriptionToUpdate.regionId = storageAccount.location;
storageDescriptionToUpdate.documentSelfLink = sd.documentSelfLink;
if (StringUtils.isEmpty(storageDescriptionToUpdate.endpointLink)) {
storageDescriptionToUpdate.endpointLink = sd.endpointLink;
}
storageDescriptionToUpdate.computeHostLink = sd.computeHostLink;
// first copy
storageDescriptionToUpdate.endpointLinks = sd.endpointLinks;
// then update it
AdapterUtils.addToEndpointLinks(storageDescriptionToUpdate, context.request.endpointLink);
storageDescriptionToUpdate.tenantLinks = sd.tenantLinks;
storageDescriptionToUpdate.regionId = storageAccount.location;
// Check if SSE (encryption) is enable on azure storage account
storageDescriptionToUpdate.supportsEncryption = storageAccount.properties.encryption != null ? storageAccount.properties.encryption.services.blob.enabled : false;
// Set type of azure storage account
storageDescriptionToUpdate.type = storageAccount.sku.name;
context.storageDescriptionsForPatching.put(sd.id, sd);
return storageDescriptionToUpdate;
}).map(sd -> Operation.createPatch(this, sd.documentSelfLink).setBody(sd).setCompletion((o, e) -> {
if (e != null) {
logWarning(() -> String.format("Failed to update storage description:" + " %s", e.getMessage()));
}
})).map(o -> sendWithDeferredResult(o)).collect(java.util.stream.Collectors.toList());
DeferredResult.allOf(updates).whenComplete((ignore, e) -> {
logFine(() -> "Finished updating storage descriptions");
context.subStage = next;
handleSubStage(context);
});
}
use of org.apache.commons.lang3.StringUtils.isEmpty in project photon-model by vmware.
the class AzureCostStatsService method createQueryForComputeStatesBySubscription.
/**
* Creates a query operation to get the compute states corresponding to the specified
* subscription GUID. The list of the resultant compute states is then passed to the specified
* handler for processing.
*
* @return operation object representing the query
*/
private Operation createQueryForComputeStatesBySubscription(Context context, String subscriptionGuid, Consumer<List<ComputeState>> queryResultConsumer) {
Query azureSubscriptionsQuery = Query.Builder.create().addKindFieldClause(ComputeState.class).addCompositeFieldClause(ComputeState.FIELD_NAME_CUSTOM_PROPERTIES, EndpointAllocationTaskService.CUSTOM_PROP_ENPOINT_TYPE, PhotonModelConstants.EndpointType.azure.name()).addCompositeFieldClause(ComputeState.FIELD_NAME_CUSTOM_PROPERTIES, PhotonModelConstants.CLOUD_ACCOUNT_ID, subscriptionGuid).addFieldClause(ComputeState.FIELD_NAME_TYPE, ComputeType.ENDPOINT_HOST).addInCollectionItemClause(ComputeState.FIELD_NAME_TENANT_LINKS, context.computeHostDesc.tenantLinks).build();
QueryTask queryTask = QueryTask.Builder.createDirectTask().addOption(QueryOption.EXPAND_CONTENT).addOption(QueryOption.TOP_RESULTS).setResultLimit(QueryUtils.DEFAULT_MAX_RESULT_LIMIT).setQuery(azureSubscriptionsQuery).build();
queryTask.setDirect(true);
queryTask.tenantLinks = context.computeHostDesc.tenantLinks;
return QueryUtils.createQueryTaskOperation(this, queryTask, ServiceTypeCluster.INVENTORY_SERVICE).setCompletion((operation, exception) -> {
if (exception != null) {
getFailureConsumer(context).accept(exception);
return;
}
QueryTask responseTask = operation.getBody(QueryTask.class);
if (responseTask == null || responseTask.results == null || responseTask.results.documents == null) {
// Couldn't find compute state for subscription with specified GUID
return;
}
List<ComputeState> subscriptionComputeState = responseTask.results.documents.values().stream().map(s -> Utils.fromJson(s, ComputeState.class)).filter(cs -> !StringUtils.isEmpty(cs.endpointLink) && !CollectionUtils.isEmpty(cs.endpointLinks)).collect(Collectors.toList());
if (subscriptionComputeState == null || subscriptionComputeState.size() == 0) {
return;
}
queryResultConsumer.accept(subscriptionComputeState);
});
}
use of org.apache.commons.lang3.StringUtils.isEmpty in project photon-model by vmware.
the class AzureComputeEnumerationAdapterService method processCreateUpdateNicRequest.
/**
* Processes request for creating and updating Network interface resources.
*/
private void processCreateUpdateNicRequest(NetworkInterfaceState nic, NetworkInterfaceInner remoteNic, EnumerationContext ctx, List<DeferredResult<NetworkInterfaceState>> ops, Map<String, String> subnetPerNicId, boolean isCreate) {
nic.name = remoteNic.name();
nic.subnetLink = subnetPerNicId.get(remoteNic.id());
NicMetadata nicMeta = new NicMetadata();
nicMeta.state = nic;
nicMeta.macAddress = remoteNic.macAddress();
// else will default to original ID for PATCH requests
if (isCreate) {
nic.id = remoteNic.id();
nic.endpointLink = ctx.request.endpointLink;
AdapterUtils.addToEndpointLinks(nic, ctx.request.endpointLink);
nic.tenantLinks = ctx.parentCompute.tenantLinks;
nic.regionId = remoteNic.location();
nic.computeHostLink = ctx.parentCompute.documentSelfLink;
} else {
if (StringUtils.isEmpty(nic.endpointLink)) {
nic.endpointLink = ctx.request.endpointLink;
}
nic.endpointLinks.add(ctx.request.endpointLink);
}
List<NetworkInterfaceIPConfigurationInner> ipConfigurations = remoteNic.ipConfigurations();
if (ipConfigurations == null || ipConfigurations.isEmpty()) {
executeNicCreateUpdateRequest(nic, remoteNic, ctx, ops, nicMeta, isCreate);
return;
}
NetworkInterfaceIPConfigurationInner nicIPConf = ipConfigurations.get(0);
nic.address = nicIPConf.privateIPAddress();
if (nicIPConf.publicIPAddress() == null) {
executeNicCreateUpdateRequest(nic, remoteNic, ctx, ops, nicMeta, isCreate);
return;
}
// IP address is not directly available in NetworkInterfaceIPConfigurationInner.
// It is available as a SubResource, We use the SubResource ID of IP address from
// NetworkInterfaceIPConfigurationInner to obtain the IP address.
Consumer<Throwable> failure = e -> {
logWarning("Error getting public IP address from Azure [endpointLink:%s], [Exception:%s]", ctx.request.endpointLink, e.getMessage());
handleError(ctx, e);
};
PhotonModelUtils.runInExecutor(this.executorService, () -> {
Azure azure = ctx.azureSdkClients.getAzureClient();
azure.publicIPAddresses().getByIdAsync(nicIPConf.publicIPAddress().id()).subscribe(injectOperationContext(new Action1<PublicIPAddress>() {
@Override
public void call(PublicIPAddress publicIPAddress) {
nicMeta.publicIp = publicIPAddress.ipAddress();
if (publicIPAddress.inner().dnsSettings() != null) {
nicMeta.publicDnsName = publicIPAddress.inner().dnsSettings().fqdn();
}
executeNicCreateUpdateRequest(nic, remoteNic, ctx, ops, nicMeta, isCreate);
}
}));
}, failure);
}
use of org.apache.commons.lang3.StringUtils.isEmpty in project kie-wb-common by kiegroup.
the class BeanPropertiesProvider method getSelectorData.
@Override
public SelectorData getSelectorData(FormRenderingContext context) {
HashMap<String, String> values = new HashMap<>();
if (context instanceof FormEditorRenderingContext && context.getParentContext() != null) {
if (context.getParentContext().getModel() instanceof MultipleSubFormFieldDefinition) {
FormEditorRenderingContext editorContext = (FormEditorRenderingContext) context;
if (context.getParentContext() != null) {
MultipleSubFormFieldDefinition subForm = (MultipleSubFormFieldDefinition) context.getParentContext().getModel();
Path path = editorContext.getFormPath();
String typeName = subForm.getStandaloneClassName();
final TableColumnMeta currentMeta = (TableColumnMeta) context.getModel();
Set<String> unavailableProperties = subForm.getColumnMetas().stream().map(TableColumnMeta::getProperty).collect(Collectors.toSet());
if (currentMeta != null && !StringUtils.isEmpty(currentMeta.getProperty())) {
unavailableProperties.remove(currentMeta.getProperty());
}
modelFinderService.getModel(typeName, path).getProperties().stream().filter(property -> !unavailableProperties.contains(property.getName())).forEachOrdered(property -> values.put(property.getName(), property.getName()));
}
}
}
return new SelectorData(values, null);
}
Aggregations