本文整理汇总了Java中org.eclipse.che.api.core.model.workspace.WorkspaceConfig类的典型用法代码示例。如果您正苦于以下问题:Java WorkspaceConfig类的具体用法?Java WorkspaceConfig怎么用?Java WorkspaceConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WorkspaceConfig类属于org.eclipse.che.api.core.model.workspace包,在下文中一共展示了WorkspaceConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startWorkspace
import org.eclipse.che.api.core.model.workspace.WorkspaceConfig; //导入依赖的package包/类
@Override
public WorkspaceImpl startWorkspace(
WorkspaceConfig config, String namespace, boolean isTemporary, Map<String, String> options)
throws ServerException, NotFoundException, ConflictException, ValidationException {
checkMaxEnvironmentRam(config);
String accountId = accountManager.getByName(namespace).getId();
try (@SuppressWarnings("unused")
Unlocker u = resourcesLocks.lock(accountId)) {
checkWorkspaceResourceAvailability(accountId);
checkRuntimeResourceAvailability(accountId);
checkRamResourcesAvailability(accountId, namespace, config, null);
return super.startWorkspace(config, namespace, isTemporary, options);
}
}
示例2: checkMaxEnvironmentRam
import org.eclipse.che.api.core.model.workspace.WorkspaceConfig; //导入依赖的package包/类
@VisibleForTesting
void checkMaxEnvironmentRam(WorkspaceConfig config) throws ServerException {
if (maxRamPerEnvMB < 0) {
return;
}
for (Map.Entry<String, ? extends Environment> envEntry : config.getEnvironments().entrySet()) {
Environment env = envEntry.getValue();
final long workspaceRam = environmentRamCalculator.calculate(env);
if (workspaceRam > maxRamPerEnvMB) {
throw new LimitExceededException(
format("You are only allowed to use %d mb. RAM per workspace.", maxRamPerEnvMB),
ImmutableMap.of(
"environment_max_ram",
Long.toString(maxRamPerEnvMB),
"environment_max_ram_unit",
"mb",
"environment_ram",
Long.toString(workspaceRam),
"environment_ram_unit",
"mb"));
}
}
}
示例3: testValidateOnCreate
import org.eclipse.che.api.core.model.workspace.WorkspaceConfig; //导入依赖的package包/类
@Test
public void testValidateOnCreate() throws Exception {
FactoryCreateValidatorImpl spy = spy(createValidator);
doNothing().when(spy).validateProjects(any(FactoryDto.class));
doNothing().when(spy).validateCurrentTimeAfterSinceUntil(any(FactoryDto.class));
doNothing().when(spy).validateProjectActions(any(FactoryDto.class));
doNothing().when(workspaceConfigValidator).validateConfig(any(WorkspaceConfig.class));
// main invoke
spy.validateOnCreate(factory);
verify(spy).validateProjects(any(FactoryDto.class));
verify(spy).validateCurrentTimeAfterSinceUntil(any(FactoryDto.class));
verify(spy).validateOnCreate(any(FactoryDto.class));
verify(spy).validateProjectActions(any(FactoryDto.class));
verifyNoMoreInteractions(spy);
}
示例4: asDto
import org.eclipse.che.api.core.model.workspace.WorkspaceConfig; //导入依赖的package包/类
/** Converts {@link WorkspaceConfig} to {@link WorkspaceConfigDto}. */
public static WorkspaceConfigDto asDto(WorkspaceConfig workspace) {
List<CommandDto> commands =
workspace.getCommands().stream().map(DtoConverter::asDto).collect(toList());
List<ProjectConfigDto> projects =
workspace.getProjects().stream().map(DtoConverter::asDto).collect(toList());
Map<String, EnvironmentDto> environments =
workspace
.getEnvironments()
.entrySet()
.stream()
.collect(toMap(Map.Entry::getKey, entry -> asDto(entry.getValue())));
return newDto(WorkspaceConfigDto.class)
.withName(workspace.getName())
.withDefaultEnv(workspace.getDefaultEnv())
.withCommands(commands)
.withProjects(projects)
.withEnvironments(environments)
.withDescription(workspace.getDescription());
}
示例5: WorkspaceImpl
import org.eclipse.che.api.core.model.workspace.WorkspaceConfig; //导入依赖的package包/类
public WorkspaceImpl(
String id,
Account account,
WorkspaceConfig config,
Runtime runtime,
Map<String, String> attributes,
boolean isTemporary,
WorkspaceStatus status) {
this.id = id;
if (account != null) {
this.account = new AccountImpl(account);
}
if (config != null) {
this.config = new WorkspaceConfigImpl(config);
}
if (runtime != null) {
this.runtime =
new RuntimeImpl(runtime.getActiveEnv(), runtime.getMachines(), runtime.getOwner());
}
if (attributes != null) {
this.attributes = new HashMap<>(attributes);
}
this.isTemporary = isTemporary;
this.status = status;
}
示例6: doCreateWorkspace
import org.eclipse.che.api.core.model.workspace.WorkspaceConfig; //导入依赖的package包/类
private WorkspaceImpl doCreateWorkspace(
WorkspaceConfig config, Account account, Map<String, String> attributes, boolean isTemporary)
throws NotFoundException, ServerException, ConflictException {
WorkspaceImpl workspace =
WorkspaceImpl.builder()
.generateId()
.setConfig(config)
.setAccount(account)
.setAttributes(attributes)
.setTemporary(isTemporary)
.setStatus(STOPPED)
.build();
workspace.getAttributes().put(CREATED_ATTRIBUTE_NAME, Long.toString(currentTimeMillis()));
workspaceDao.create(workspace);
LOG.info(
"Workspace '{}/{}' with id '{}' created by user '{}'",
account.getName(),
workspace.getConfig().getName(),
workspace.getId(),
sessionUserNameOrUndefined());
eventService.publish(new WorkspaceCreatedEvent(workspace));
return workspace;
}
示例7: setUp
import org.eclipse.che.api.core.model.workspace.WorkspaceConfig; //导入依赖的package包/类
@BeforeMethod
public void setUp() throws Exception {
when(workspace.getId()).thenReturn("wside-123877234580");
when(workspace.getNamespace()).thenReturn("my-namespace");
when(workspace.getConfig()).thenReturn(mock(WorkspaceConfig.class));
when(workspace.getConfig().getName()).thenReturn("my-name");
when(runtimeCtx.getOutputChannel()).thenReturn(URI.create("ws://localhost/output/websocket"));
when(runtimes.getRuntimeContext(workspace.getId())).thenReturn(Optional.of(runtimeCtx));
final UriBuilder uriBuilder = new UriBuilderImpl();
uriBuilder.uri(URI_BASE);
when(serviceContextMock.getServiceUriBuilder()).thenReturn(uriBuilder);
when(serviceContextMock.getBaseUriBuilder()).thenReturn(uriBuilder);
linksGenerator = new WorkspaceLinksGenerator(runtimes, "ws://localhost");
expectedStoppedLinks = new HashMap<>();
expectedStoppedLinks.put(LINK_REL_SELF, "http://localhost/api/workspace/wside-123877234580");
expectedStoppedLinks.put(LINK_REL_IDE_URL, "http://localhost/my-namespace/my-name");
expectedRunningLinks = new HashMap<>(expectedStoppedLinks);
expectedRunningLinks.put(LINK_REL_ENVIRONMENT_STATUS_CHANNEL, "ws://localhost");
expectedRunningLinks.put(
LINK_REL_ENVIRONMENT_OUTPUT_CHANNEL, "ws://localhost/output/websocket");
}
示例8: getsWorkspacesAvailableForUserWithRuntimes
import org.eclipse.che.api.core.model.workspace.WorkspaceConfig; //导入依赖的package包/类
@Test
public void getsWorkspacesAvailableForUserWithRuntimes() throws Exception {
final WorkspaceConfig config = createConfig();
final WorkspaceImpl workspace1 = createAndMockWorkspace(config, NAMESPACE_1);
final WorkspaceImpl workspace2 = createAndMockWorkspace(config, NAMESPACE_2);
final TestInternalRuntime runtime2 = mockRuntime(workspace2, RUNNING);
when(workspaceDao.getWorkspaces(eq(NAMESPACE_1), anyInt(), anyLong()))
.thenReturn(new Page<>(asList(workspace1, workspace2), 0, 2, 2));
final Page<WorkspaceImpl> result = workspaceManager.getWorkspaces(NAMESPACE_1, true, 30, 0);
assertEquals(result.getItems().size(), 2);
final WorkspaceImpl res1 = result.getItems().get(0);
assertEquals(
res1.getStatus(), STOPPED, "Workspace status wasn't changed from STARTING to STOPPED");
assertNull(res1.getRuntime(), "Workspace has unexpected runtime");
assertFalse(res1.isTemporary(), "Workspace must be permanent");
final WorkspaceImpl res2 = result.getItems().get(1);
assertEquals(
res2.getStatus(),
RUNNING,
"Workspace status wasn't changed to the runtime instance status");
assertEquals(res2.getRuntime(), runtime2, "Workspace doesn't have expected runtime");
assertFalse(res2.isTemporary(), "Workspace must be permanent");
}
示例9: createAndMockWorkspace
import org.eclipse.che.api.core.model.workspace.WorkspaceConfig; //导入依赖的package包/类
private WorkspaceImpl createAndMockWorkspace(WorkspaceConfig cfg, String namespace)
throws Exception {
WorkspaceImpl workspace =
WorkspaceImpl.builder()
.generateId()
.setConfig(cfg)
.setAccount(new AccountImpl("id", namespace, "type"))
.setStatus(STOPPED)
.build();
when(workspaceDao.get(workspace.getId())).thenReturn(workspace);
when(workspaceDao.get(workspace.getConfig().getName(), workspace.getNamespace()))
.thenReturn(workspace);
when(workspaceDao.get(workspace.getConfig().getName(), NAMESPACE_1)).thenReturn(workspace);
when(workspaceDao.getByNamespace(eq(workspace.getNamespace()), anyInt(), anyLong()))
.thenReturn(new Page<>(singletonList(workspace), 0, 1, 1));
when(workspaceDao.getByNamespace(eq(NAMESPACE_1), anyInt(), anyLong()))
.thenReturn(new Page<>(singletonList(workspace), 0, 1, 1));
when(workspaceDao.getWorkspaces(eq(USER_ID), anyInt(), anyLong()))
.thenReturn(new Page<>(singletonList(workspace), 0, 1, 1));
return workspace;
}
示例10: createWorkspace
import org.eclipse.che.api.core.model.workspace.WorkspaceConfig; //导入依赖的package包/类
@Override
public WorkspaceImpl createWorkspace(
WorkspaceConfig config, String namespace, @Nullable Map<String, String> attributes)
throws ServerException, ConflictException, NotFoundException, ValidationException {
checkMaxEnvironmentRam(config);
String accountId = accountManager.getByName(namespace).getId();
try (@SuppressWarnings("unused")
Unlocker u = resourcesLocks.lock(accountId)) {
checkWorkspaceResourceAvailability(accountId);
return super.createWorkspace(config, namespace, attributes);
}
}
示例11: checkRamResourcesAvailability
import org.eclipse.che.api.core.model.workspace.WorkspaceConfig; //导入依赖的package包/类
@VisibleForTesting
void checkRamResourcesAvailability(
String accountId, String namespace, WorkspaceConfig config, @Nullable String envName)
throws NotFoundException, ServerException, ConflictException {
final Environment environment =
config.getEnvironments().get(firstNonNull(envName, config.getDefaultEnv()));
final ResourceImpl ramToUse =
new ResourceImpl(
RamResourceType.ID,
environmentRamCalculator.calculate(environment),
RamResourceType.UNIT);
try {
resourceUsageManager.checkResourcesAvailability(accountId, singletonList(ramToUse));
} catch (NoEnoughResourcesException e) {
final Resource requiredRam =
e.getRequiredResources().get(0); // starting of workspace requires only RAM resource
final Resource availableRam =
getResourceOrDefault(
e.getAvailableResources(), RamResourceType.ID, 0, RamResourceType.UNIT);
final Resource usedRam =
getResourceOrDefault(
resourceUsageManager.getUsedResources(accountId),
RamResourceType.ID,
0,
RamResourceType.UNIT);
throw new LimitExceededException(
format(
"Workspace %s/%s needs %s to start. Your account has %s available and %s in use. "
+ "The workspace can't be start. Stop other workspaces or grant more resources.",
namespace,
config.getName(),
printResourceInfo(requiredRam),
printResourceInfo(availableRam),
printResourceInfo(usedRam)));
}
}
示例12: setUp
import org.eclipse.che.api.core.model.workspace.WorkspaceConfig; //导入依赖的package包/类
@BeforeMethod
public void setUp() {
removeLocalProjectsFolderOnWorkspaceRemove =
spy(new RemoveLocalProjectsFolderOnWorkspaceRemove(projectsFolderPathProvider));
WorkspaceConfig workspaceConfig = mock(WorkspaceConfig.class);
when(workspaceConfig.getName()).thenReturn(WORKSPACE_NAME);
when(workspace.getId()).thenReturn(WORKSPACE_ID);
when(workspace.getNamespace()).thenReturn(WORKSPACE_NAMESPACE);
when(workspace.getConfig()).thenReturn(workspaceConfig);
}
示例13: getAll
import org.eclipse.che.api.core.model.workspace.WorkspaceConfig; //导入依赖的package包/类
@Override
public Set<ProjectConfig> getAll() throws ServerException {
WorkspaceConfig config = workspaceDto().getConfig();
Set<ProjectConfig> projectConfigs = new HashSet<>(config.getProjects());
return unmodifiableSet(projectConfigs);
}
示例14: FactoryImpl
import org.eclipse.che.api.core.model.workspace.WorkspaceConfig; //导入依赖的package包/类
public FactoryImpl(
String id,
String name,
String version,
WorkspaceConfig workspace,
Author creator,
Policies policies,
Ide ide,
Button button) {
this.id = id;
this.name = name;
this.version = version;
if (workspace != null) {
this.workspace = new WorkspaceConfigImpl(workspace);
}
if (creator != null) {
this.creator = new AuthorImpl(creator);
}
if (policies != null) {
this.policies = new PoliciesImpl(policies);
}
if (ide != null) {
this.ide = new IdeImpl(ide);
}
if (button != null) {
this.button = new ButtonImpl(button);
}
}
示例15: createWorkspaceConfig
import org.eclipse.che.api.core.model.workspace.WorkspaceConfig; //导入依赖的package包/类
private static WorkspaceConfig createWorkspaceConfig(String type, String location) {
return WorkspaceConfigImpl.builder()
.setName(WORKSPACE_NAME)
.setEnvironments(singletonMap("env1", new EnvironmentImpl(createEnvDto())))
.setProjects(createProjects(type, location))
.build();
}