org.elasticsearch.cluster.metadata.RepositoriesMetaData Java Examples

The following examples show how to use org.elasticsearch.cluster.metadata.RepositoriesMetaData. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RestGetRepositoriesAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    final String[] repositories = request.paramAsStringArray("repository", Strings.EMPTY_ARRAY);
    GetRepositoriesRequest getRepositoriesRequest = getRepositoryRequest(repositories);
    getRepositoriesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getRepositoriesRequest.masterNodeTimeout()));
    getRepositoriesRequest.local(request.paramAsBoolean("local", getRepositoriesRequest.local()));
    settingsFilter.addFilterSettingParams(request);
    client.admin().cluster().getRepositories(getRepositoriesRequest, new RestBuilderListener<GetRepositoriesResponse>(channel) {
        @Override
        public RestResponse buildResponse(GetRepositoriesResponse response, XContentBuilder builder) throws Exception {
            builder.startObject();
            for (RepositoryMetaData repositoryMetaData : response.repositories()) {
                RepositoriesMetaData.toXContent(repositoryMetaData, builder, request);
            }
            builder.endObject();

            return new BytesRestResponse(OK, builder);
        }
    });
}
 
Example #2
Source File: CreateDropRepositoryAnalyzerTest.java    From crate with Apache License 2.0 6 votes vote down vote up
@Before
public void prepare() {
    RepositoriesMetaData repositoriesMetaData = new RepositoriesMetaData(
        Collections.singletonList(
            new RepositoryMetaData(
                "my_repo",
                "fs",
                Settings.builder().put("location", "/tmp/my_repo").build()
            )));
    ClusterState clusterState = ClusterState.builder(new ClusterName("testing"))
        .metaData(MetaData.builder()
                      .putCustom(RepositoriesMetaData.TYPE, repositoriesMetaData))
        .build();
    ClusterServiceUtils.setState(clusterService, clusterState);
    e = SQLExecutor.builder(clusterService).build();
    plannerContext = e.getPlannerContext(clusterService.state());
    repositoryParamValidator = new RepositoryParamValidator(Map.of(
        "fs", new TypeSettings(FsRepository.mandatorySettings(), FsRepository.optionalSettings())
    ));
}
 
Example #3
Source File: SnapshotRestoreAnalyzerTest.java    From crate with Apache License 2.0 6 votes vote down vote up
@Before
public void prepare() throws IOException {
    RepositoriesMetaData repositoriesMetaData = new RepositoriesMetaData(
        Collections.singletonList(
            new RepositoryMetaData(
                "my_repo",
                "fs",
                Settings.builder().put("location", "/tmp/my_repo").build()
        )));
    ClusterState clusterState = ClusterState.builder(new ClusterName("testing"))
        .metaData(MetaData.builder()
            .putCustom(RepositoriesMetaData.TYPE, repositoriesMetaData))
        .build();
    ClusterServiceUtils.setState(clusterService, clusterState);
    e = SQLExecutor.builder(clusterService)
        .addTable(USER_TABLE_DEFINITION)
        .addTable(TEST_DOC_LOCATIONS_TABLE_DEFINITION)
        .addPartitionedTable(TEST_PARTITIONED_TABLE_DEFINITION, TEST_PARTITIONED_TABLE_PARTITIONS)
        .addBlobTable("create blob table my_blobs")
        .build();
    plannerContext = e.getPlannerContext(clusterService.state());
}
 
Example #4
Source File: S3RepositoryPluginAnalyzerTest.java    From crate with Apache License 2.0 6 votes vote down vote up
@Before
public void prepare() {
    RepositoriesMetaData repositoriesMetaData = new RepositoriesMetaData(
        Collections.singletonList(
            new RepositoryMetaData(
                "my_repo",
                "fs",
                Settings.builder().put("location", "/tmp/my_repo").build()
            )));
    ClusterState clusterState = ClusterState.builder(new ClusterName("testing"))
        .metaData(MetaData.builder()
                      .putCustom(RepositoriesMetaData.TYPE, repositoriesMetaData))
        .build();
    ClusterServiceUtils.setState(clusterService, clusterState);
    e = SQLExecutor.builder(clusterService).build();
    plannerContext = e.getPlannerContext(clusterService.state());
    repositoryParamValidator = new RepositoryParamValidator(
        Map.of("s3", new TypeSettings(List.of(), S3Repository.optionalSettings()))
    );
}
 
Example #5
Source File: AzureRepositoryAnalyzerTest.java    From crate with Apache License 2.0 6 votes vote down vote up
@Before
public void prepare() {
    RepositoriesMetaData repositoriesMetaData = new RepositoriesMetaData(
        Collections.singletonList(
            new RepositoryMetaData(
                "my_repo",
                "fs",
                Settings.builder().put("location", "/tmp/my_repo").build()
            )));
    ClusterState clusterState = ClusterState.builder(new ClusterName("testing"))
        .metaData(MetaData.builder()
                      .putCustom(RepositoriesMetaData.TYPE, repositoriesMetaData))
        .build();
    ClusterServiceUtils.setState(clusterService, clusterState);
    e = SQLExecutor.builder(clusterService).build();
    plannerContext = e.getPlannerContext(clusterService.state());
    repositoryParamValidator = new RepositoryParamValidator(
        Map.of("azure", new TypeSettings(AzureRepository.mandatorySettings(), AzureRepository.optionalSettings()))
    );
}
 
Example #6
Source File: SysRepositories.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private void addRepositories(@Nullable RepositoriesMetaData repositoriesMetaData) {
    if (repositoriesMetaData == null) {
        return;
    }
    for (RepositoryMetaData repositoryMetaData : repositoriesMetaData.repositories()) {
        SysRepository repository = new SysRepository(
                repositoryMetaData.name(),
                repositoryMetaData.type(),
                repositoryMetaData.settings().getAsStructuredMap());
        repositoriesTable.put(repositoryMetaData.name(), repository);
    }
}
 
Example #7
Source File: SysRepositories.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void clusterChanged(ClusterChangedEvent event) {
    if (repositoriesChanged(event)) {
        RepositoriesMetaData repositoriesMetaData = event.state().metaData().custom(RepositoriesMetaData.TYPE);
        repositoriesTable = new HashMap<>(repositoriesMetaData.repositories().size());
        addRepositories(repositoriesMetaData);
    }
}
 
Example #8
Source File: SysRepositories.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private boolean repositoriesChanged(ClusterChangedEvent event) {
    RepositoriesMetaData previousRepositoriesMetaData = event.previousState().metaData().custom(RepositoriesMetaData.TYPE);
    RepositoriesMetaData repositoriesMetaData = event.state().metaData().custom(RepositoriesMetaData.TYPE);
    if (previousRepositoriesMetaData == null && repositoriesMetaData == null) {
        return false;
    } else if (previousRepositoriesMetaData == null || repositoriesMetaData == null) {
        return true;
    }
    return !repositoriesMetaData.repositories().equals(previousRepositoriesMetaData.repositories());
}
 
Example #9
Source File: RepositoryService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Nullable
public RepositoryMetaData getRepository(String repositoryName) {
    RepositoriesMetaData repositories = clusterService.state().metaData().custom(RepositoriesMetaData.TYPE);
    if (repositories != null) {
        return repositories.repository(repositoryName);
    }
    return null;
}
 
Example #10
Source File: SnapshotsService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
/**
 * Validates snapshot request
 *
 * @param request snapshot request
 * @param state   current cluster state
 */
private void validate(SnapshotRequest request, ClusterState state) {
    RepositoriesMetaData repositoriesMetaData = state.getMetaData().custom(RepositoriesMetaData.TYPE);
    if (repositoriesMetaData == null || repositoriesMetaData.repository(request.repository()) == null) {
        throw new RepositoryMissingException(request.repository());
    }
    validate(new SnapshotId(request.repository(), request.name()));
}
 
Example #11
Source File: ClusterModule.java    From crate with Apache License 2.0 5 votes vote down vote up
public static List<Entry> getNamedWriteables() {
    List<Entry> entries = new ArrayList<>();
    // Cluster State
    registerClusterCustom(entries, SnapshotsInProgress.TYPE, SnapshotsInProgress::new, SnapshotsInProgress::readDiffFrom);
    registerClusterCustom(entries, RestoreInProgress.TYPE, RestoreInProgress::new, RestoreInProgress::readDiffFrom);
    registerClusterCustom(entries, SnapshotDeletionsInProgress.TYPE, SnapshotDeletionsInProgress::new,
        SnapshotDeletionsInProgress::readDiffFrom);
    // Metadata
    registerMetaDataCustom(entries, RepositoriesMetaData.TYPE, RepositoriesMetaData::new, RepositoriesMetaData::readDiffFrom);
    registerMetaDataCustom(entries, IndexGraveyard.TYPE, IndexGraveyard::new, IndexGraveyard::readDiffFrom);
    return entries;
}
 
Example #12
Source File: ClusterModule.java    From crate with Apache License 2.0 5 votes vote down vote up
public static List<NamedXContentRegistry.Entry> getNamedXWriteables() {
    List<NamedXContentRegistry.Entry> entries = new ArrayList<>();
    // Metadata
    entries.add(new NamedXContentRegistry.Entry(MetaData.Custom.class, new ParseField(RepositoriesMetaData.TYPE),
        RepositoriesMetaData::fromXContent));
    entries.add(new NamedXContentRegistry.Entry(MetaData.Custom.class, new ParseField(IndexGraveyard.TYPE),
        IndexGraveyard::fromXContent));
    return entries;
}
 
Example #13
Source File: SnapshotsService.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Validates snapshot request
 *
 * @param repositoryName repository name
 * @param snapshotName snapshot name
 * @param state   current cluster state
 */
private static void validate(String repositoryName, String snapshotName, ClusterState state) {
    RepositoriesMetaData repositoriesMetaData = state.getMetaData().custom(RepositoriesMetaData.TYPE);
    if (repositoriesMetaData == null || repositoriesMetaData.repository(repositoryName) == null) {
        throw new RepositoryMissingException(repositoryName);
    }
    validate(repositoryName, snapshotName);
}
 
Example #14
Source File: RepositoryService.java    From crate with Apache License 2.0 5 votes vote down vote up
@Nullable
public RepositoryMetaData getRepository(String repositoryName) {
    RepositoriesMetaData repositories = clusterService.state().metaData().custom(RepositoriesMetaData.TYPE);
    if (repositories != null) {
        return repositories.repository(repositoryName);
    }
    return null;
}
 
Example #15
Source File: SysRepositories.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Inject
public SysRepositories(ClusterService clusterService) {
    RepositoriesMetaData repositoriesMetaData = clusterService.state().metaData().custom(RepositoriesMetaData.TYPE);
    addRepositories(repositoriesMetaData);
    clusterService.add(this);
}
 
Example #16
Source File: AccessControlMayExecuteTest.java    From crate with Apache License 2.0 4 votes vote down vote up
@Before
public void setUpSQLExecutor() throws Exception {
    validationCallArguments = new ArrayList<>();
    RepositoriesMetaData repositoriesMetaData = new RepositoriesMetaData(
        singletonList(
            new RepositoryMetaData(
                "my_repo",
                "fs",
                Settings.builder().put("location", "/tmp/my_repo").build()
        )));
    ClusterState clusterState = ClusterState.builder(clusterService.state())
        .metaData(MetaData.builder(clusterService.state().metaData())
            .putCustom(RepositoriesMetaData.TYPE, repositoriesMetaData))
        .build();
    ClusterServiceUtils.setState(clusterService, clusterState);

    user = new User("normal", ImmutableSet.of(), ImmutableSet.of(), null) {
        @Override
        public boolean hasPrivilege(Privilege.Type type, Privilege.Clazz clazz, String ident, String defaultSchema) {
            validationCallArguments.add(Lists.newArrayList(type, clazz, ident, user.name()));
            return true;
        }
    };
    superUser = new User("crate", EnumSet.of(User.Role.SUPERUSER), ImmutableSet.of(), null) {
        @Override
        public boolean hasPrivilege(Privilege.Type type, Privilege.Clazz clazz, @Nullable String ident, String defaultSchema) {
            validationCallArguments.add(Lists.newArrayList(type, clazz, ident, superUser.name()));
            return true;
        }
    };
    userManager = new UserManagerService(null, null,
        null, null, mock(SysTableRegistry.class), clusterService, new DDLClusterStateService()) {
        @Nullable
        @Override
        public User findUser(String userName) {
            if ("crate".equals(userName)) {
                return superUser;
            }
            return super.findUser(userName);
        }
    };

    e = SQLExecutor.builder(clusterService)
        .addBlobTable("create blob table blobs")
        .enableDefaultTables()
        .setUser(superUser)
        .addView(new RelationName("doc", "v1"), "select * from users")
        .setUserManager(userManager)
        .build();
}