Skip to content
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
2 changes: 1 addition & 1 deletion build-project.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ set -e

HDFS_VERSION=$1

mvn install:install-file -pl smart-tests -Dos.arch=x86_64
mvn install:install-file -pl smart-tests
mvn clean install -Pdist,web-ui,hadoop-"${HDFS_VERSION}" -DskipTests
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@

import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

/**
* A common action factory for action providers to use.
Expand All @@ -34,12 +36,9 @@ public abstract class AbstractActionFactory implements ActionFactory {
private static final List<Class<? extends SmartAction>> COMMON_ACTIONS = Arrays.asList(
EchoAction.class,
SleepAction.class,
SyncAction.class,
ExecAction.class
);

protected abstract List<Class<? extends SmartAction>> supportedActionClasses();

@Override
public Map<String, Class<? extends SmartAction>> getSupportedActions() {
Map<String, Class<? extends SmartAction>> supportedActions = new HashMap<>();
Expand All @@ -51,12 +50,33 @@ public Map<String, Class<? extends SmartAction>> getSupportedActions() {
return supportedActions;
}

@Override
public Set<ActionMetadata> getActionMetadata() {
Set<ActionMetadata> actionMetadata = new HashSet<>();
COMMON_ACTIONS.forEach(action ->
toActionMetadata(action).ifPresent(actionMetadata::add));
supportedActionClasses().forEach(action ->
toActionMetadata(action).ifPresent(actionMetadata::add));

return actionMetadata;
}

protected abstract List<Class<? extends SmartAction>> supportedActionClasses();

private Optional<ActionMetadata> toActionMetadata(Class<? extends SmartAction> actionClass) {
return actionSignature(actionClass)
.map(signature -> new ActionMetadata(signature.actionId(), signature.usage()));
}

private void addActionInfo(
Map<String, Class<? extends SmartAction>> supportedActions,
Class<? extends SmartAction> actionClass) {

Optional.ofNullable(actionClass.getAnnotation(ActionSignature.class))
actionSignature(actionClass)
.map(ActionSignature::actionId)
.ifPresent(actionId -> supportedActions.put(actionId, actionClass));
}

private Optional<ActionSignature> actionSignature(Class<? extends SmartAction> actionClass) {
return Optional.ofNullable(actionClass.getAnnotation(ActionSignature.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.smartdata.action;

import java.util.Map;
import java.util.Set;

/**
* Action factory interface. Either built-in or user defined actions will be
Expand All @@ -30,4 +31,6 @@ public interface ActionFactory {
* @return supported actions
*/
Map<String, Class<? extends SmartAction>> getSupportedActions();

Set<ActionMetadata> getActionMetadata();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.smartdata.action;

import lombok.Data;

@Data
public class ActionMetadata {
private final String name;
private final String usage;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
*/
package org.smartdata.action;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

Expand All @@ -29,12 +31,21 @@
*/
@Slf4j
public class ActionRegistry {
private final Map<String, Class<? extends SmartAction>> actions = new HashMap<>();
@Getter
private final Set<ActionMetadata> actionMetadata;
private final Map<String, Class<? extends SmartAction>> actions;

public ActionRegistry(Collection<ActionFactory> factories) {
this.actions = new HashMap<>();
this.actionMetadata = new HashSet<>();

factories.stream()
.map(ActionFactory::getSupportedActions)
.forEach(actions::putAll);

factories.stream()
.map(ActionFactory::getActionMetadata)
.forEach(actionMetadata::addAll);
}

public Set<String> registeredActions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@
*/
package org.smartdata.metrics;

import org.smartdata.model.BaseFileInfo;

import java.sql.SQLException;
import java.util.Collection;
import java.util.List;
import java.util.Map;

public interface GeneralFileInfoSource {
Map<String, Long> getPathsToIdsMapping(Collection<String> paths) throws SQLException;

List<String> getFilePathsByPrefix(String path);

BaseFileInfo getBaseFileInfo(String path);
}
100 changes: 11 additions & 89 deletions smart-common/src/main/java/org/smartdata/model/BackUpInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,101 +17,23 @@
*/
package org.smartdata.model;

import java.util.Objects;
import lombok.Builder;
import lombok.Data;
import lombok.RequiredArgsConstructor;

import static org.smartdata.utils.StringUtil.ssmPatternToRegex;

@Data
@RequiredArgsConstructor
@Builder(toBuilder = true)
public class BackUpInfo {
private long rid;
private String src;
private String dest;
private long period; // in milliseconds
private String srcPattern;
private final long rid;
private final String src;
private final String dest;
private final long period; // in milliseconds
private final String srcPattern;

public BackUpInfo(long rid, String src, String dest, long period) {
this(rid, src, dest, period, ssmPatternToRegex(src + "*"));
}

public BackUpInfo(long rid, String src, String dest, long period, String srcPattern) {
this.rid = rid;
this.src = src;
this.dest = dest;
this.period = period;
this.srcPattern = srcPattern;
}

public BackUpInfo() {
}

public long getRid() {
return rid;
}

public void setRid(long rid) {
this.rid = rid;
}

public String getSrc() {
return src;
}

public void setSrc(String src) {
this.src = src;
}

public String getDest() {
return dest;
}

public void setDest(String dest) {
this.dest = dest;
}

public long getPeriod() {
return period;
}

public void setPeriod(long period) {
this.period = period;
}

public String getSrcPattern() {
return srcPattern;
}

public void setSrcPattern(String srcPattern) {
this.srcPattern = srcPattern;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
BackUpInfo that = (BackUpInfo) o;
return rid == that.rid
&& period == that.period
&& Objects.equals(src, that.src)
&& Objects.equals(dest, that.dest)
&& Objects.equals(srcPattern, that.srcPattern);
}

@Override
public int hashCode() {
return Objects.hash(rid, src, dest, period, srcPattern);
}

@Override
public String toString() {
return "BackUpInfo{"
+ "rid=" + rid
+ ", src='" + src + '\''
+ ", dest='" + dest + '\''
+ ", period=" + period
+ ", srcPattern='" + srcPattern + '\''
+ '}';
}
}
26 changes: 26 additions & 0 deletions smart-common/src/main/java/org/smartdata/model/BaseFileInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.smartdata.model;

public interface BaseFileInfo {
String getPath();

long getLength();

boolean isDir();
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
@Data
@AllArgsConstructor
@Builder(setterPrefix = "set")
public class FileInfo {
public class FileInfo implements BaseFileInfo {
private String path;
private long fileId;
private long length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public class SmartEngine extends AbstractService {
private SmartPrincipalManager smartPrincipalManager;
@Getter
private CachedFilesManager cachedFilesManager;
@Getter
private ActionRegistry actionRegistry;

private final List<SmartService> services;

Expand All @@ -85,7 +87,7 @@ public void init() throws IOException {

FileSystemContext fsContext = FileSystemContext.fromConfig(conf);

ActionRegistry actionRegistry = new ActionRegistry(fsContext.actionFactories());
actionRegistry = new ActionRegistry(fsContext.actionFactories());

cmdletManager = CmdletManager.builder()
.context(serverContext)
Expand All @@ -103,6 +105,7 @@ public void init() throws IOException {
.actionRegistry(actionRegistry)
.smartPrincipalManager(smartPrincipalManager)
.executorPlugins(fsContext.ruleExecutorPlugins(serverContext, cmdletManager))
.smartObjectSupplier(fsContext.smartObjectSupplier())
.build();

services.add(ruleManager);
Expand Down
Loading