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

GEODE-7409: get latest PDX configuration of cluster in REST API for M… #4320

Merged
merged 5 commits into from
Nov 14, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ javadoc/org/apache/geode/management/runtime/CacheServerInfo.html
javadoc/org/apache/geode/management/runtime/GatewayReceiverInfo.html
javadoc/org/apache/geode/management/runtime/MemberInformation.html
javadoc/org/apache/geode/management/runtime/OperationResult.html
javadoc/org/apache/geode/management/runtime/PdxInfo.html
javadoc/org/apache/geode/management/runtime/RebalanceRegionResult.html
javadoc/org/apache/geode/management/runtime/RebalanceResult.html
javadoc/org/apache/geode/management/runtime/RuntimeInfo.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ public <T extends AbstractConfiguration<R>, R extends RuntimeInfo> ClusterManage
ConfigurationResult<T, R> response = new ConfigurationResult<>(element);

responses.add(response);
// do not gather runtime if this type of CacheElement is RespondWith<RuntimeInfo>
if (!hasRuntimeInfo) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@
import org.apache.geode.management.configuration.AbstractConfiguration;
import org.apache.geode.management.configuration.GatewayReceiver;
import org.apache.geode.management.configuration.Member;
import org.apache.geode.management.configuration.Pdx;
import org.apache.geode.management.configuration.Region;
import org.apache.geode.management.internal.CacheElementOperation;
import org.apache.geode.management.internal.configuration.realizers.ConfigurationRealizer;
import org.apache.geode.management.internal.configuration.realizers.GatewayReceiverRealizer;
import org.apache.geode.management.internal.configuration.realizers.MemberRealizer;
import org.apache.geode.management.internal.configuration.realizers.PdxRealizer;
import org.apache.geode.management.internal.configuration.realizers.RegionConfigRealizer;
import org.apache.geode.management.runtime.RuntimeInfo;

Expand All @@ -49,6 +51,7 @@ public class CacheRealizationFunction implements InternalFunction<List> {
realizers.put(Region.class, new RegionConfigRealizer());
realizers.put(GatewayReceiver.class, new GatewayReceiverRealizer());
realizers.put(Member.class, new MemberRealizer());
realizers.put(Pdx.class, new PdxRealizer());
}

@Override
Expand Down Expand Up @@ -104,7 +107,7 @@ public RealizationResult executeUpdate(FunctionContext<List> context,
RealizationResult result = new RealizationResult();
result.setMemberName(context.getMemberName());

if (realizer == null) {
if (realizer == null || realizer.isReadyOnly()) {
return result.setMessage("Server '" + context.getMemberName()
+ "' needs to be restarted for this configuration change to be realized.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@ default boolean exists(T config, InternalCache cache) {
RealizationResult update(T config, InternalCache cache);

RealizationResult delete(T config, InternalCache cache);

default boolean isReadyOnly() {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.apache.geode.management.internal.configuration.realizers;

import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.management.configuration.Pdx;
import org.apache.geode.management.runtime.PdxInfo;
import org.apache.geode.pdx.PdxSerializer;

public class PdxRealizer extends ReadOnlyConfigurationRealizer<Pdx, PdxInfo> {
@Override
public PdxInfo get(Pdx config, InternalCache cache) {
PdxInfo info = new PdxInfo();
info.setReadSerialized(cache.getPdxReadSerialized());
if (cache.getPdxPersistent()) {
info.setDiskStoreName(cache.getPdxDiskStore());
}
info.setIgnoreUnreadFields(cache.getPdxIgnoreUnreadFields());
PdxSerializer pdxSerializer = cache.getPdxSerializer();
if (pdxSerializer != null) {
info.setPdxSerializer(pdxSerializer.getClass().getName());
dschneider-pivotal marked this conversation as resolved.
Show resolved Hide resolved
}
return info;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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.apache.geode.management.internal.configuration.realizers;

import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.management.api.RealizationResult;
import org.apache.geode.management.configuration.AbstractConfiguration;
import org.apache.geode.management.runtime.RuntimeInfo;

public abstract class ReadOnlyConfigurationRealizer<T extends AbstractConfiguration<R>, R extends RuntimeInfo>
implements ConfigurationRealizer<T, R> {
public final RealizationResult create(T config, InternalCache cache) {
throw new IllegalStateException("should not be invoked");
}

public final RealizationResult update(T config, InternalCache cache) {
throw new IllegalStateException("should not be invoked");
}

public final RealizationResult delete(T config, InternalCache cache) {
throw new IllegalStateException("should not be invoked");
}

public abstract R get(T config, InternalCache cache);

public final boolean isReadyOnly() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ org/apache/geode/management/configuration/RegionType,false
org/apache/geode/management/runtime/CacheServerInfo,true,1,bindAddress:java/lang/String,isRunning:boolean,maxConnections:int,maxThreads:int,port:int
org/apache/geode/management/runtime/GatewayReceiverInfo,false,bindAddress:java/lang/String,connectedSenders:java/lang/String[],hostnameForSenders:java/lang/String,port:int,running:boolean,senderCount:int
org/apache/geode/management/runtime/MemberInformation,true,1,cacheServerList:java/util/List,cacheXmlFilePath:java/lang/String,clientCount:int,cpuUsage:double,groups:java/lang/String,heapUsage:long,host:java/lang/String,hostedRegions:java/util/Set,httpServiceBindAddress:java/lang/String,httpServicePort:int,id:java/lang/String,initHeapSize:long,isCoordinator:boolean,isSecured:boolean,isServer:boolean,locatorPort:int,locators:java/lang/String,logFilePath:java/lang/String,maxHeapSize:long,offHeapMemorySize:java/lang/String,processId:int,serverBindAddress:java/lang/String,statArchiveFilePath:java/lang/String,status:java/lang/String,webSSL:boolean,workingDirPath:java/lang/String
org/apache/geode/management/runtime/PdxInfo,false,diskStoreName:java/lang/String,ignoreUnreadFields:boolean,pdxSerializer:java/lang/String,readSerialized:boolean
org/apache/geode/management/runtime/RuntimeInfo,false,memberName:java/lang/String
org/apache/geode/management/runtime/RuntimeRegionInfo,false,entryCount:long
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* 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.apache.geode.management.internal.configuration.realizers;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import org.junit.Before;
import org.junit.Test;

import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.management.runtime.PdxInfo;

public class PdxRealizerTest {
private PdxRealizer pdxRealizer;
private InternalCache cache;

@Before
public void before() throws Exception {
pdxRealizer = new PdxRealizer();
cache = mock(InternalCache.class);
}

@Test
public void getPdxInformation() {
when(cache.getPdxReadSerialized()).thenReturn(true);
PdxInfo pdxInfo = pdxRealizer.get(null, cache);
assertThat(pdxInfo.isReadSerialized()).isTrue();
assertThat(pdxInfo.isIgnoreUnreadFields()).isFalse();
}

@Test
public void persistent() throws Exception {
when(cache.getPdxPersistent()).thenReturn(false);
when(cache.getPdxDiskStore()).thenReturn("test");
PdxInfo pdxInfo = pdxRealizer.get(null, cache);
assertThat(pdxInfo.getDiskStoreName()).isNull();

when(cache.getPdxPersistent()).thenReturn(true);
pdxInfo = pdxRealizer.get(null, cache);
assertThat(pdxInfo.getDiskStoreName()).isEqualTo("test");
}

@Test
public void readOnly() {
assertThat(pdxRealizer.isReadyOnly()).isTrue();
assertThatThrownBy(() -> pdxRealizer.create(null, cache))
.isInstanceOf(IllegalStateException.class);
assertThatThrownBy(() -> pdxRealizer.delete(null, cache))
.isInstanceOf(IllegalStateException.class);
assertThatThrownBy(() -> pdxRealizer.update(null, cache))
.isInstanceOf(IllegalStateException.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
import com.fasterxml.jackson.annotation.JsonIgnore;

import org.apache.geode.annotations.Experimental;
import org.apache.geode.management.runtime.RuntimeInfo;
import org.apache.geode.management.runtime.PdxInfo;

/**
* Used to configure PDX serialization for a cache.
*/
@Experimental
public class Pdx extends AbstractConfiguration<RuntimeInfo> {
public class Pdx extends AbstractConfiguration<PdxInfo> {
public static final String PDX_ID = "PDX";
public static final String PDX_ENDPOINT = "/configurations/pdx";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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.apache.geode.management.runtime;

import org.apache.geode.annotations.Experimental;

@Experimental
public class PdxInfo extends RuntimeInfo {
jinmeiliao marked this conversation as resolved.
Show resolved Hide resolved
private boolean readSerialized;
private String diskStoreName;
private boolean ignoreUnreadFields;
private String pdxSerializer;

public boolean isReadSerialized() {
return readSerialized;
}

public void setReadSerialized(boolean readSerialized) {
this.readSerialized = readSerialized;
}

public String getDiskStoreName() {
return diskStoreName;
}

public void setDiskStoreName(String diskStoreName) {
this.diskStoreName = diskStoreName;
}

public boolean isIgnoreUnreadFields() {
return ignoreUnreadFields;
}

public void setIgnoreUnreadFields(boolean ignoreUnreadFields) {
this.ignoreUnreadFields = ignoreUnreadFields;
}

public String getPdxSerializer() {
return pdxSerializer;
}

public void setPdxSerializer(String pdxSerializer) {
this.pdxSerializer = pdxSerializer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import java.util.List;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
Expand All @@ -36,13 +38,15 @@
import org.apache.geode.distributed.internal.InternalConfigurationPersistenceService;
import org.apache.geode.distributed.internal.InternalLocator;
import org.apache.geode.management.api.ClusterManagementException;
import org.apache.geode.management.api.ClusterManagementGetResult;
import org.apache.geode.management.api.ClusterManagementRealizationResult;
import org.apache.geode.management.api.ClusterManagementResult;
import org.apache.geode.management.api.ClusterManagementService;
import org.apache.geode.management.api.RealizationResult;
import org.apache.geode.management.configuration.Pdx;
import org.apache.geode.management.internal.rest.LocatorWebContext;
import org.apache.geode.management.internal.rest.PlainLocatorContextLoader;
import org.apache.geode.management.runtime.PdxInfo;
import org.apache.geode.test.dunit.rules.ClusterStartupRule;
import org.apache.geode.test.dunit.rules.MemberVM;

Expand Down Expand Up @@ -89,6 +93,7 @@ InternalLocator getLocator() {

@Test
public void configureWithNoServer() throws Exception {
pdxType.setReadSerialized(true);
ClusterManagementRealizationResult result = client.create(pdxType);
assertThat(result.isSuccessful()).isTrue();
assertThat(result.getStatusCode()).isEqualTo(ClusterManagementResult.StatusCode.OK);
Expand All @@ -99,12 +104,18 @@ public void configureWithNoServer() throws Exception {
assertThatThrownBy(() -> client.create(pdxType))
.isInstanceOf(ClusterManagementException.class)
.hasMessageContaining("ENTITY_EXISTS: Pdx 'PDX' already exists in group cluster");

// verify the get
ClusterManagementGetResult<Pdx, PdxInfo> getResult = client.get(new Pdx());
Pdx configResult = getResult.getConfigResult();
assertThat(configResult.isReadSerialized()).isTrue();
assertThat(getResult.getRuntimeResult()).hasSize(0);
}

@Test
public void configureWithARunningServer() {
MemberVM server = cluster.startServerVM(1, webContext.getLocator().getPort());

pdxType.setReadSerialized(true);
ClusterManagementRealizationResult result = client.create(pdxType);
assertThat(result.isSuccessful()).isTrue();
assertThat(result.getStatusCode()).isEqualTo(ClusterManagementResult.StatusCode.OK);
Expand All @@ -125,6 +136,14 @@ public void configureWithARunningServer() {
.isInstanceOf(ClusterManagementException.class)
.hasMessageContaining("ENTITY_EXISTS: Pdx 'PDX' already exists in group cluster");

// verify the get
ClusterManagementGetResult<Pdx, PdxInfo> getResult = client.get(new Pdx());
Pdx configResult = getResult.getConfigResult();
assertThat(configResult.isReadSerialized()).isTrue();
List<PdxInfo> runtimeResults = getResult.getRuntimeResult();
assertThat(runtimeResults).hasSize(1);
assertThat(runtimeResults.get(0).isReadSerialized()).isFalse();

server.stop();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public static void beforeClass() throws JsonProcessingException {

testContexts.add(new TestContext(post("/v1/configurations/pdx"), "CLUSTER:MANAGE")
.setContent(mapper.writeValueAsString(new PdxType())));
testContexts.add(new TestContext(get("/v1/configurations/pdx"), "CLUSTER:READ"));

testContexts.add(new TestContext(post("/v1/operations/rebalances"), "DATA:MANAGE")
.setContent(mapper.writeValueAsString(new RebalanceOperation())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import org.apache.geode.management.api.ClusterManagementGetResult;
import org.apache.geode.management.api.ClusterManagementResult;
import org.apache.geode.management.configuration.Pdx;
import org.apache.geode.management.runtime.PdxInfo;

@RestController("pdxManagement")
@RequestMapping(URI_VERSION)
Expand All @@ -48,4 +51,11 @@ public ResponseEntity<ClusterManagementResult> configurePdx(
ClusterManagementResult result = clusterManagementService.create(pdxType);
return new ResponseEntity<>(result, HttpStatus.CREATED);
}

@ApiOperation(value = "get pdx")
@PreAuthorize("@securityService.authorize('CLUSTER', 'READ')")
@GetMapping(PDX_ENDPOINT)
public ClusterManagementGetResult<Pdx, PdxInfo> getPDX() {
return clusterManagementService.get(new Pdx());
}
}