use of org.eclipse.che.api.workspace.server.model.impl.WarningImpl in project devspaces-images by redhat-developer.
the class DeploymentMetadataProvisionerTest method shouldAddWarningIfLabelAttributeInInvalidFormat.
@Test
public void shouldAddWarningIfLabelAttributeInInvalidFormat() throws NotFoundException, ServerException, InfrastructureException {
// given
when(workspace.getAttributes()).thenReturn(ImmutableMap.of(WS_DEPLOYMENT_LABELS_ATTR_NAME, "L1~V1"));
when(workspaceManager.getWorkspace(eq(WS_ID))).thenReturn(workspace);
Deployment deployment = newDeployment();
doReturn(ImmutableMap.of(DEPLOYMENT_NAME, deployment)).when(k8sEnv).getDeploymentsCopy();
// when
provisioner.provision(k8sEnv, identity);
// then
ArgumentCaptor<WarningImpl> argumentCaptor = ArgumentCaptor.forClass(WarningImpl.class);
verify(k8sEnv).addWarning(argumentCaptor.capture());
assertEquals(argumentCaptor.getAllValues().size(), 1);
assertEquals(argumentCaptor.getValue(), new WarningImpl(NOT_ABLE_TO_PROVISION_WORKSPACE_DEPLOYMENT_LABELS_OR_ANNOTATIONS, "Not able to provision workspace " + WS_ID + " deployment labels or annotations because of invalid configuration. Reason: 'Chunk [L1~V1] is not a valid entry'"));
}
use of org.eclipse.che.api.workspace.server.model.impl.WarningImpl in project devspaces-images by redhat-developer.
the class DeploymentMetadataProvisionerTest method shouldAddWarningIfAnnotationAttributeInInvalidFormat.
@Test
public void shouldAddWarningIfAnnotationAttributeInInvalidFormat() throws NotFoundException, ServerException, InfrastructureException {
// given
when(workspace.getAttributes()).thenReturn(ImmutableMap.of(WS_DEPLOYMENT_ANNOTATIONS_ATTR_NAME, "A1~V1"));
when(workspaceManager.getWorkspace(eq(WS_ID))).thenReturn(workspace);
Deployment deployment = newDeployment();
doReturn(ImmutableMap.of(DEPLOYMENT_NAME, deployment)).when(k8sEnv).getDeploymentsCopy();
// when
provisioner.provision(k8sEnv, identity);
// then
ArgumentCaptor<WarningImpl> argumentCaptor = ArgumentCaptor.forClass(WarningImpl.class);
verify(k8sEnv).addWarning(argumentCaptor.capture());
assertEquals(argumentCaptor.getAllValues().size(), 1);
assertEquals(argumentCaptor.getValue(), new WarningImpl(NOT_ABLE_TO_PROVISION_WORKSPACE_DEPLOYMENT_LABELS_OR_ANNOTATIONS, "Not able to provision workspace " + WS_ID + " deployment labels or annotations because of invalid configuration. Reason: 'Chunk [A1~V1] is not a valid entry'"));
}
use of org.eclipse.che.api.workspace.server.model.impl.WarningImpl in project devspaces-images by redhat-developer.
the class GitConfigProvisionerTest method testShouldExpectWarningWhenPreferenceManagerThrowsServerException.
@Test
public void testShouldExpectWarningWhenPreferenceManagerThrowsServerException() throws Exception {
when(preferenceManager.find(eq("id"), eq("theia-user-preferences"))).thenThrow(new ServerException("message"));
gitConfigProvisioner.provision(k8sEnv, runtimeIdentity);
verifyNoMoreInteractions(runtimeIdentity);
List<Warning> warnings = k8sEnv.getWarnings();
assertEquals(warnings.size(), 1);
Warning actualWarning = warnings.get(0);
String warnMsg = format(Warnings.EXCEPTION_IN_USER_MANAGEMENT_DURING_GIT_PROVISION_MESSAGE_FMT, "message");
Warning expectedWarning = new WarningImpl(Warnings.EXCEPTION_IN_USER_MANAGEMENT_DURING_GIT_PROVISION_WARNING_CODE, warnMsg);
assertEquals(expectedWarning, actualWarning);
}
use of org.eclipse.che.api.workspace.server.model.impl.WarningImpl in project devspaces-images by redhat-developer.
the class PreviewUrlCommandProvisioner method injectsPreviewUrlToCommands.
/**
* Go through all commands, find matching service and exposed host. Then construct full preview
* url from this data and set it as Command's parameter under `previewUrl` key.
*
* @param env environment to get commands
* @param namespace current kubernetes namespace where we're looking for services and ingresses
*/
private void injectsPreviewUrlToCommands(E env, KubernetesNamespace namespace) throws InfrastructureException {
if (env.getCommands() == null) {
return;
}
List<T> exposureObjects = loadExposureObjects(namespace);
List<Service> services = namespace.services().get();
for (CommandImpl command : env.getCommands().stream().filter(c -> c.getPreviewUrl() != null).collect(Collectors.toList())) {
Optional<Service> foundService = Services.findServiceWithPort(services, command.getPreviewUrl().getPort());
if (!foundService.isPresent()) {
String message = String.format("unable to find service for port '%s' for command '%s'", command.getPreviewUrl().getPort(), command.getName());
LOG.warn(message);
env.addWarning(new WarningImpl(NOT_ABLE_TO_PROVISION_OBJECTS_FOR_PREVIEW_URL, String.format(NOT_ABLE_TO_PROVISION_OBJECTS_FOR_PREVIEW_URL_MESSAGE, message)));
continue;
}
Optional<String> foundHost = findHostForServicePort(exposureObjects, foundService.get(), command.getPreviewUrl().getPort());
if (foundHost.isPresent()) {
command.getAttributes().put(PREVIEW_URL_ATTRIBUTE, foundHost.get());
} else {
String message = String.format("unable to find ingress for service '%s' and port '%s'", foundService.get(), command.getPreviewUrl().getPort());
LOG.warn(message);
env.addWarning(new WarningImpl(NOT_ABLE_TO_PROVISION_OBJECTS_FOR_PREVIEW_URL, String.format(NOT_ABLE_TO_PROVISION_OBJECTS_FOR_PREVIEW_URL_MESSAGE, message)));
}
}
}
use of org.eclipse.che.api.workspace.server.model.impl.WarningImpl in project devspaces-images by redhat-developer.
the class SshKeysProvisioner method provision.
@Override
@Traced
public void provision(KubernetesEnvironment k8sEnv, RuntimeIdentity identity) throws InfrastructureException {
String workspaceId = identity.getWorkspaceId();
TracingTags.WORKSPACE_ID.set(workspaceId);
List<SshPairImpl> vcsSshPairs = getVcsSshPairs(k8sEnv, identity);
List<SshPairImpl> systemSshPairs = getSystemSshPairs(k8sEnv, identity);
List<SshPairImpl> allSshPairs = new ArrayList<>(vcsSshPairs);
allSshPairs.addAll(systemSshPairs);
List<String> invalidSshKeyNames = allSshPairs.stream().filter(keyPair -> !isValidSshKeyPair(keyPair)).map(SshPairImpl::getName).collect(toList());
if (!invalidSshKeyNames.isEmpty()) {
String message = format(Warnings.SSH_KEYS_WILL_NOT_BE_MOUNTED_MESSAGE, invalidSshKeyNames.toString(), identity.getWorkspaceId());
LOG.warn(message);
k8sEnv.addWarning(new WarningImpl(Warnings.SSH_KEYS_WILL_NOT_BE_MOUNTED, message));
runtimeEventsPublisher.sendRuntimeLogEvent(message, ZonedDateTime.now().toString(), identity);
}
doProvisionSshKeys(allSshPairs.stream().filter(this::isValidSshKeyPair).collect(toList()), k8sEnv, workspaceId);
doProvisionVcsSshConfig(vcsSshPairs.stream().filter(this::isValidSshKeyPair).collect(toList()), k8sEnv, workspaceId);
}
Aggregations