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 handler to clean up project config registry #9229

Merged
merged 3 commits into from
Mar 27, 2018
Merged
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 @@ -28,6 +28,7 @@
import org.eclipse.che.api.project.server.impl.RegisteredProject;
import org.eclipse.che.api.project.server.impl.RegisteredProjectFactory;
import org.eclipse.che.api.project.server.impl.RootDirCreationHandler;
import org.eclipse.che.api.project.server.impl.RootDirRemovalHandler;
import org.eclipse.che.api.project.server.impl.ValidatingProjectManager;
import org.eclipse.che.api.project.server.impl.WorkspaceProjectSynchronizer;
import org.eclipse.che.api.project.server.impl.ZipProjectImporter;
Expand Down Expand Up @@ -62,6 +63,7 @@ protected void configure() {
bind(ProjectHandlerRegistry.class);

bind(RootDirCreationHandler.class).asEagerSingleton();
bind(RootDirRemovalHandler.class).asEagerSingleton();

bind(ProjectManager.class).to(ValidatingProjectManager.class);
bind(ProjectSynchronizer.class).to(WorkspaceProjectSynchronizer.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.api.project.server.impl;

import static org.eclipse.che.api.fs.server.WsPathUtils.ROOT;

import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.eclipse.che.api.core.ServerException;
import org.eclipse.che.api.project.server.ProjectManager;
import org.eclipse.che.api.watcher.server.FileWatcherManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Cleans up project config registry when some project is removed bypassing {@link ProjectManager}
*
* @author Roman Nikitenko
*/
@Singleton
public class RootDirRemovalHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(RootDirRemovalHandler.class);

private final ProjectSynchronizer projectSynchronizer;
private final ProjectConfigRegistry projectConfigRegistry;
private final FileWatcherManager fileWatcherManager;

@Inject
public RootDirRemovalHandler(
ProjectSynchronizer projectSynchronizer,
ProjectConfigRegistry projectConfigRegistry,
FileWatcherManager fileWatcherManager) {
this.projectSynchronizer = projectSynchronizer;
this.projectConfigRegistry = projectConfigRegistry;
this.fileWatcherManager = fileWatcherManager;
}

@PostConstruct
private void registerOperation() {
fileWatcherManager.registerByPath(ROOT, arg -> {}, arg -> {}, this::consumeDelete);
}

private void consumeDelete(String wsPath) {
try {
if (projectConfigRegistry.isRegistered(wsPath)) {
projectConfigRegistry.remove(wsPath);
projectSynchronizer.synchronize();
}
} catch (ServerException e) {
LOGGER.error(
"Removing project '{}' is detected. Cleaning project config registry is failed: {}",
wsPath,
e.getMessage());
}
}
}