Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add generateName to devfile metadata with persistance #14158

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public interface Workspace {
/** Returns the identifier of this workspace instance. It is mandatory and unique. */
String getId();

/** Returns name of the workspace instance. */
String getName();

/**
* Returns the namespace of the current workspace instance. Workspace name is unique for
* workspaces in the same namespace.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ public interface Metadata {

/** @return the name of the devfile */
String getName();

String getGenerateName();
}
12 changes: 2 additions & 10 deletions dashboard/src/components/api/workspace/workspace-data-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ export class WorkspaceDataManager {
* @param workspace workspace name
*/
getName(workspace: che.IWorkspace): string {
if (workspace.config) {
return workspace.config.name;
} else if (workspace.devfile) {
return workspace.devfile.metadata.name;
}
return workspace.name
}

/**
Expand All @@ -43,11 +39,7 @@ export class WorkspaceDataManager {
* @param name workspace name
*/
setName(workspace: che.IWorkspace, name: string): void {
if (workspace.config) {
workspace.config.name = name;
} else if (workspace.devfile) {
workspace.devfile.metadata.name = name;
}
workspace.name = name;
}

/**
Expand Down
1 change: 1 addition & 0 deletions dashboard/src/components/typings/che.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ declare namespace che {

export interface IWorkspace {
id?: string;
name?: string;
projects?: any;
links?: {
ide?: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,19 @@ public static AccountImpl createAccount() {
}

public static WorkspaceImpl createWorkspace() {
return new WorkspaceImpl(
generate("wsId", 8),
createAccount(),
new WorkspaceConfigImpl(
generate("wsName", 8),
"description",
"defEnv",
emptyList(),
emptyList(),
emptyMap(),
emptyMap()));
return WorkspaceImpl.builder()
.setId(generate("wsId", 8))
.setAccount(createAccount())
.setConfig(
new WorkspaceConfigImpl(
generate("wsName", 8),
"description",
"defEnv",
emptyList(),
emptyList(),
emptyMap(),
emptyMap()))
.build();
}

public static KubernetesRuntimeState createRuntimeState(WorkspaceImpl workspace) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.eclipse.che.api.core.Page;
import org.eclipse.che.api.workspace.server.WorkspaceManager;
import org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl;
import org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl.WorkspaceImplBuilder;
import org.eclipse.che.multiuser.resource.api.type.WorkspaceResourceType;
import org.eclipse.che.multiuser.resource.model.Resource;
import org.mockito.InjectMocks;
Expand Down Expand Up @@ -89,13 +90,12 @@ public void shouldReturnUsedWorkspacesForGivenAccount() throws Exception {
when(accountManager.getById(any())).thenReturn(account);
when(account.getName()).thenReturn("testAccount");

WorkspaceImplBuilder wsBuilder = WorkspaceImpl.builder();

when(workspaceManager.getByNamespace(anyString(), anyBoolean(), anyInt(), anyLong()))
.thenReturn(
new Page<>(
Arrays.asList(new WorkspaceImpl(), new WorkspaceImpl(), new WorkspaceImpl()),
0,
3,
3));
Arrays.asList(wsBuilder.build(), wsBuilder.build(), wsBuilder.build()), 0, 3, 3));

Optional<Resource> usedWorkspacesOpt =
workspaceResourceUsageTracker.getUsedResource("account123");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ public static WorkspaceConfigImpl createWorkspaceConfig(String id) {
}

public static WorkspaceImpl createWorkspace(String id, Account account) {
return new WorkspaceImpl(id, account, createWorkspaceConfig(id));
return WorkspaceImpl.builder()
.setId(id)
.setAccount(account)
.setConfig(createWorkspaceConfig(id))
.build();
}

public static SshPairImpl createSshPair(String owner, String service, String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.eclipse.che.api.core.NotFoundException;
import org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl;
import org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl;
import org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl.WorkspaceImplBuilder;
import org.eclipse.che.commons.test.tck.TckListener;
import org.eclipse.che.commons.test.tck.repository.TckRepository;
import org.eclipse.che.commons.test.tck.repository.TckRepositoryException;
Expand Down Expand Up @@ -75,24 +76,25 @@ public void createEntities() throws Exception {

AccountImpl account = new AccountImpl("account1", "accountName", "test");
accountRepository.createAll(Collections.singletonList(account));
WorkspaceImplBuilder wsBuilder = WorkspaceImpl.builder().setAccount(account);
workspaceRepository.createAll(
Arrays.asList(
new WorkspaceImpl(
"ws0",
account,
new WorkspaceConfigImpl("ws-name0", "", "cfg0", null, null, null, null)),
new WorkspaceImpl(
"ws1",
account,
new WorkspaceConfigImpl("ws-name1", "", "cfg1", null, null, null, null)),
new WorkspaceImpl(
"ws2",
account,
new WorkspaceConfigImpl("ws-name2", "", "cfg2", null, null, null, null)),
new WorkspaceImpl(
"id_10",
account,
new WorkspaceConfigImpl("ws-name10", "", "cfg1", null, null, null, null))));
wsBuilder
.setId("ws0")
.setConfig(new WorkspaceConfigImpl("ws-name0", "", "cfg0", null, null, null, null))
.build(),
wsBuilder
.setId("ws1")
.setConfig(new WorkspaceConfigImpl("ws-name1", "", "cfg1", null, null, null, null))
.build(),
wsBuilder
.setId("ws2")
.setConfig(new WorkspaceConfigImpl("ws-name2", "", "cfg2", null, null, null, null))
.build(),
wsBuilder
.setId("id_10")
.setConfig(new WorkspaceConfigImpl("ws-name10", "", "cfg1", null, null, null, null))
.build()));

storedKeyPairs = new SignatureKeyPairImpl[COUNT_KEY_PAIRS];
kpg = KeyPairGenerator.getInstance(ALGORITHM);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.eclipse.che.api.user.server.model.impl.UserImpl;
import org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl;
import org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl;
import org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl.WorkspaceImplBuilder;
import org.eclipse.che.commons.test.tck.TckResourcesCleaner;
import org.eclipse.che.multiuser.permission.workspace.server.model.impl.WorkerImpl;
import org.eclipse.che.multiuser.permission.workspace.server.spi.jpa.MultiuserJpaWorkspaceDao;
Expand Down Expand Up @@ -60,19 +61,22 @@ public void setupEntities() throws Exception {
};

account = new AccountImpl("account1", "accountName", "test");
WorkspaceImplBuilder wsBuilder = WorkspaceImpl.builder().setAccount(account);

workspaces =
new WorkspaceImpl[] {
new WorkspaceImpl(
"ws1",
account,
new WorkspaceConfigImpl("wrksp1", "", "cfg1", null, null, null, null)),
new WorkspaceImpl(
"ws2",
account,
new WorkspaceConfigImpl("wrksp2", "", "cfg2", null, null, null, null)),
new WorkspaceImpl(
"ws3", account, new WorkspaceConfigImpl("wrksp3", "", "cfg3", null, null, null, null))
wsBuilder
.setId("ws1")
.setConfig(new WorkspaceConfigImpl("wrksp1", "", "cfg1", null, null, null, null))
.build(),
wsBuilder
.setId("ws2")
.setConfig(new WorkspaceConfigImpl("wrksp2", "", "cfg2", null, null, null, null))
.build(),
wsBuilder
.setId("ws3")
.setConfig(new WorkspaceConfigImpl("wrksp3", "", "cfg3", null, null, null, null))
.build()
};
Injector injector = Guice.createInjector(new WorkspaceTckModule());
manager = injector.getInstance(EntityManager.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void shouldThrowServerExceptionOnExistsWhenRuntimeExceptionOccursInDoGetM

final Account account = new AccountImpl("accountId", "namespace", "test");
final WorkspaceImpl workspace =
WorkspaceImpl.builder().setId("workspaceId").setAccount(account).build();
WorkspaceImpl.builder().setId("workspaceId").setAccount(account).setName("wsname").build();

// Persist the account
manager.getTransaction().begin();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ public void setupEntities() throws Exception {
};

workspace =
new WorkspaceImpl(
"ws1", account, new WorkspaceConfigImpl("", "", "cfg1", null, null, null, null));
WorkspaceImpl.builder()
.setId("ws1")
.setAccount(account)
.setConfig(new WorkspaceConfigImpl("", "", "cfg1", null, null, null, null))
.build();

workers =
new WorkerImpl[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.eclipse.che.api.user.server.model.impl.UserImpl;
import org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl;
import org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl;
import org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl.WorkspaceImplBuilder;
import org.eclipse.che.commons.test.tck.TckListener;
import org.eclipse.che.commons.test.tck.repository.TckRepository;
import org.eclipse.che.commons.test.tck.repository.TckRepositoryException;
Expand Down Expand Up @@ -82,20 +83,21 @@ public void setUp() throws TckRepositoryException {

AccountImpl account = new AccountImpl("account1", "accountName", "test");
accountRepository.createAll(Collections.singletonList(account));
WorkspaceImplBuilder wsBuilder = WorkspaceImpl.builder().setAccount(account);
workspaceRepository.createAll(
Arrays.asList(
new WorkspaceImpl(
"ws0",
account,
new WorkspaceConfigImpl("ws-name0", "", "cfg0", null, null, null, null)),
new WorkspaceImpl(
"ws1",
account,
new WorkspaceConfigImpl("ws-name1", "", "cfg1", null, null, null, null)),
new WorkspaceImpl(
"ws2",
account,
new WorkspaceConfigImpl("ws-name2", "", "cfg2", null, null, null, null))));
wsBuilder
.setId("ws0")
.setConfig(new WorkspaceConfigImpl("ws-name0", "", "cfg0", null, null, null, null))
.build(),
wsBuilder
.setId("ws1")
.setConfig(new WorkspaceConfigImpl("ws-name1", "", "cfg1", null, null, null, null))
.build(),
wsBuilder
.setId("ws2")
.setConfig(new WorkspaceConfigImpl("ws-name2", "", "cfg2", null, null, null, null))
.build()));

workerRepository.createAll(
Stream.of(workers).map(WorkerImpl::new).collect(Collectors.toList()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,8 @@ private static WorkspaceConfigImpl createWorkspaceConfig(String name) {

private static WorkspaceImpl createWorkspace(String id, AccountImpl account, String name) {
final WorkspaceConfigImpl wCfg = createWorkspaceConfig(name);
// Workspace
final WorkspaceImpl workspace = new WorkspaceImpl();
workspace.setId(id);
workspace.setAccount(account);
wCfg.setName(name);
workspace.setConfig(wCfg);
return workspace;
// Workspace
return WorkspaceImpl.builder().setId(id).setAccount(account).setConfig(wCfg).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
@DTO
public interface WorkspaceDto extends Workspace {

@Override
String getName();

WorkspaceDto withName(String name);

@Override
WorkspaceConfigDto getConfig();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,10 @@ public interface MetadataDto extends Metadata {

void setName(String name);

@Override
String getGenerateName();

MetadataDto withName(String name);

MetadataDto withGenerateName(String generateName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public static WorkspaceDto asDto(Workspace workspace) {
WorkspaceDto workspaceDto =
newDto(WorkspaceDto.class)
.withId(workspace.getId())
.withName(workspace.getName())
.withStatus(workspace.getStatus())
.withNamespace(workspace.getNamespace())
.withTemporary(workspace.isTemporary())
Expand Down Expand Up @@ -422,7 +423,9 @@ public static MachineDto asDto(Machine machine) {

/** Converts {@link Metadata} to {@link MetadataDto}. */
public static MetadataDto asDto(Metadata metadata) {
return newDto(MetadataDto.class).withName(metadata.getName());
return newDto(MetadataDto.class)
.withName(metadata.getName())
.withGenerateName(metadata.getGenerateName());
}

private DtoConverter() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public WorkspaceConfig convert(Devfile devfile) throws ServerException {
* @throws DevfileRecipeFormatException when content of the file specified in recipe type
* component is empty or its format is invalid
*/
public WorkspaceConfigImpl devFileToWorkspaceConfig(
WorkspaceConfigImpl devFileToWorkspaceConfig(
DevfileImpl devfile, FileContentProvider contentProvider) throws DevfileException {
checkArgument(devfile != null, "Devfile must not be null");
checkArgument(contentProvider != null, "Content provider must not be null");
Expand All @@ -102,7 +102,9 @@ public WorkspaceConfigImpl devFileToWorkspaceConfig(

WorkspaceConfigImpl config = new WorkspaceConfigImpl();

config.setName(devfile.getName());
if (devfile.getName() != null) {
config.setName(devfile.getName());
}

for (Command command : devfile.getCommands()) {
CommandImpl com = commandConverter.toWorkspaceCommand(command, contentProvider);
Expand Down
Loading