Skip to content
Snippets Groups Projects
Commit 0c590daf authored by Neelesh Thakur's avatar Neelesh Thakur
Browse files

add endpoint to disable auto index creation

parent e790b8b8
Branches
Tags
2 merge requests!346Merge branch 'aws-integration' into 'master',!282disable default index creation
// Copyright © Schlumberger
//
// Licensed 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.opengroup.osdu.indexer.api;
import lombok.extern.java.Log;
import org.opengroup.osdu.indexer.logging.AuditLogger;
import org.opengroup.osdu.indexer.service.IClusterConfigurationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.annotation.RequestScope;
import java.io.IOException;
import java.util.ArrayList;
@Log
@RestController
@RequestMapping("/partitions/settings")
@RequestScope
public class DataPartitionSettingsApi {
private static final String OPS = "users.datalake.ops";
@Autowired
private IClusterConfigurationService clusterConfigurationService;
@Autowired
private AuditLogger auditLogger;
@PreAuthorize("@authorizationFilter.hasPermission('" + OPS + "')")
@PostMapping
public ResponseEntity<?> partitionInit() throws IOException {
this.clusterConfigurationService.updateClusterConfiguration();
this.auditLogger.getConfigurePartition(new ArrayList<>());
return new ResponseEntity<>(org.springframework.http.HttpStatus.OK);
}
}
......@@ -57,6 +57,9 @@ public class AuditEvents {
private static final String INDEX_MAPPING_UPDATE_SUCCESS = "Successfully updated index mapping";
private static final String INDEX_MAPPING_UPDATE_FAILURE = "Failed updating index mapping";
private static final String CONFIGURE_PARTITION_ACTION_ID = "IN0012";
private static final String CONFIGURE_PARTITION_OPERATION = "Data partition cluster configuration update";
private final String user;
public AuditEvents(String user) {
......@@ -209,6 +212,17 @@ public class AuditEvents {
.build();
}
public AuditPayload getConfigurePartitionEvent(List<String> resources) {
return AuditPayload.builder()
.action(AuditAction.UPDATE)
.status(AuditStatus.FAILURE)
.actionId(CONFIGURE_PARTITION_ACTION_ID)
.message(CONFIGURE_PARTITION_OPERATION)
.resources(resources)
.user(this.user)
.build();
}
public AuditPayload getIndexMappingUpdateEvent(List<String> resources, boolean isSuccess) {
if (isSuccess) {
return AuditPayload.builder()
......
......@@ -100,6 +100,10 @@ public class AuditLogger {
this.writeLog(this.getAuditEvents().getIndexMappingUpdateEvent(resources,false));
}
public void getConfigurePartition(List<String> resources) {
this.writeLog(this.getAuditEvents().getConfigurePartitionEvent(resources));
}
private void writeLog(AuditPayload log) {
this.logger.audit(log);
}
......
// Copyright © Schlumberger
//
// Licensed 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.opengroup.osdu.indexer.service;
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest;
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.opengroup.osdu.indexer.util.ElasticClientHandler;
import org.springframework.beans.factory.annotation.Autowired;
import java.io.IOException;
public class ClusterConfigurationServiceImpl implements IClusterConfigurationService {
@Autowired
private ElasticClientHandler elasticClientHandler;
@Override
public boolean updateClusterConfiguration() throws IOException {
ClusterUpdateSettingsRequest request = new ClusterUpdateSettingsRequest();
Settings persistentSettings =
Settings.builder()
.put("action.auto_create_index", "false")
.build();
request.persistentSettings(persistentSettings);
request.timeout(TimeValue.timeValueMinutes(1));
try (RestHighLevelClient client = this.elasticClientHandler.createRestClient()) {
ClusterUpdateSettingsResponse response = client.cluster().putSettings(request, RequestOptions.DEFAULT);
return response.isAcknowledged();
}
}
}
// Copyright © Schlumberger
//
// Licensed 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.opengroup.osdu.indexer.service;
import java.io.IOException;
public interface IClusterConfigurationService {
boolean updateClusterConfiguration() throws IOException;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment