Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
192 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...java/com/netflix/genie/web/agent/inspectors/impl/RejectAllJobsAgentMetadataInspector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* | ||
* Copyright 2019 Netflix, Inc. | ||
* | ||
* 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 com.netflix.genie.web.agent.inspectors.impl; | ||
|
||
import com.netflix.genie.common.internal.dto.v4.AgentClientMetadata; | ||
import com.netflix.genie.common.internal.jobs.JobConstants; | ||
import com.netflix.genie.web.agent.inspectors.AgentMetadataInspector; | ||
import com.netflix.genie.web.agent.inspectors.InspectionReport; | ||
import org.springframework.core.env.Environment; | ||
|
||
import javax.validation.Valid; | ||
|
||
/** | ||
* An {@link AgentMetadataInspector} that accepts or rejects all agents based on the value of an environment property. | ||
* This mechanism allows temporarily disabling all new inbound jobs while at the same time keeping the servers running. | ||
* | ||
* @author mprimi | ||
* @since 4.0.0 | ||
*/ | ||
public class RejectAllJobsAgentMetadataInspector implements AgentMetadataInspector { | ||
private Environment environment; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param environment the environment | ||
*/ | ||
public RejectAllJobsAgentMetadataInspector(final Environment environment) { | ||
this.environment = environment; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public InspectionReport inspect(@Valid final AgentClientMetadata agentClientMetadata) { | ||
final boolean jobSubmissionEnabled = this.environment.getProperty( | ||
JobConstants.JOB_SUBMISSION_ENABLED_PROPERTY_KEY, | ||
Boolean.class, | ||
true | ||
); | ||
|
||
if (jobSubmissionEnabled) { | ||
return new InspectionReport( | ||
InspectionReport.Decision.ACCEPT, | ||
"Job submission is enabled" | ||
); | ||
} else { | ||
final String message = environment.getProperty( | ||
JobConstants.JOB_SUBMISSION_DISABLED_MESSAGE_KEY, | ||
String.class, | ||
JobConstants.JOB_SUBMISSION_DISABLED_DEFAULT_MESSAGE | ||
); | ||
return new InspectionReport( | ||
InspectionReport.Decision.REJECT, | ||
message | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...om/netflix/genie/web/agent/inspectors/impl/RejectAllJobsAgentMetadataInspectorSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* | ||
* Copyright 2019 Netflix, Inc. | ||
* | ||
* 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 com.netflix.genie.web.agent.inspectors.impl | ||
|
||
import com.netflix.genie.common.internal.dto.v4.AgentClientMetadata | ||
import com.netflix.genie.common.internal.jobs.JobConstants | ||
import com.netflix.genie.web.agent.inspectors.InspectionReport | ||
import org.springframework.core.env.Environment | ||
import spock.lang.Specification | ||
|
||
class RejectAllJobsAgentMetadataInspectorSpec extends Specification { | ||
RejectAllJobsAgentMetadataInspector inspector | ||
Environment environment | ||
AgentClientMetadata agentClientMetadata | ||
|
||
void setup() { | ||
this.agentClientMetadata = Mock(AgentClientMetadata) | ||
this.environment = Mock(Environment) | ||
this.inspector = new RejectAllJobsAgentMetadataInspector(environment) | ||
} | ||
|
||
def "Inspect"() { | ||
String rejectMessage = "No!" | ||
InspectionReport inspectionReport | ||
|
||
when: | ||
inspectionReport = inspector.inspect(agentClientMetadata) | ||
|
||
then: | ||
1 * environment.getProperty(JobConstants.JOB_SUBMISSION_ENABLED_PROPERTY_KEY, Boolean, true) >> true | ||
inspectionReport.getDecision() == InspectionReport.Decision.ACCEPT | ||
!inspectionReport.getMessage().isEmpty() | ||
|
||
when: | ||
inspectionReport = inspector.inspect(agentClientMetadata) | ||
|
||
then: | ||
1 * environment.getProperty(JobConstants.JOB_SUBMISSION_ENABLED_PROPERTY_KEY, Boolean, true) >> false | ||
1 * environment.getProperty(JobConstants.JOB_SUBMISSION_DISABLED_MESSAGE_KEY, String, JobConstants.JOB_SUBMISSION_DISABLED_DEFAULT_MESSAGE) >> rejectMessage | ||
inspectionReport.getDecision() == InspectionReport.Decision.REJECT | ||
inspectionReport.getMessage() == rejectMessage | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters