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

PAYARA-1076 make LazyBootPersistence manager more null safe on misconfiguration #1110

Merged
merged 1 commit into from
Sep 25, 2016
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
Original file line number Diff line number Diff line change
@@ -1,16 +1,41 @@
/*
* Copyright (c) 2014, 2016 Payara Foundation. All rights reserved.

* The contents of this file are subject to the terms of the Common Development
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2016 Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* https://github.com/payara/Payara/blob/master/LICENSE.txt
* See the License for the specific
* language governing permissions and limitations under the License.

*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
* file and include the License file at glassfish/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* The Payara Foundation designates this particular file as subject to the "Classpath"
* exception as provided by the Payara Foundation in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package fish.payara.jbatch.persistence.rdbms;

Expand Down Expand Up @@ -297,9 +322,12 @@ private void internalInit(IBatchConfig ibc1) {
} else if (database.contains("Microsoft SQL Server")) {
lazyProxy = new SQLServerPersistenceManager();
lazyProxy.init(ibc1);
} else {
lazyProxy = new NullPersistenceManager(ibc.getDatabaseConfigurationBean().getJndiName(), "{0} Datasource database type is not recognised as supported it's type is " + database);
}
}catch (SQLException ex) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.SEVERE, "Failed to get connecion to determine database type", ex);
lazyProxy = new NullPersistenceManager(dataSourceName,"{0} is not configured correctly. JBatch could not get a connection to the database");
} finally {
if (conn != null) {
try {
Expand All @@ -309,7 +337,9 @@ private void internalInit(IBatchConfig ibc1) {
}
}
}
}
} else {
lazyProxy = new NullPersistenceManager(dataSourceName,"Configured JNDI Name {0} for JBatch Datasource is NOT a datasource");
}
}catch (NamingException ex) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource", ex);
lazyProxy = new NullPersistenceManager(ibc.getDatabaseConfigurationBean().getJndiName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,244 +45,250 @@
class NullPersistenceManager implements IPersistenceManagerService {

private final String datasourceName;
private final String message;

NullPersistenceManager(String datasourceName) {
this(datasourceName,"Unable to find JBatch configured DataSource {0}");
}

NullPersistenceManager(String datasourceName, String message) {
this.datasourceName = datasourceName;
this.message = message;
}

@Override
public int jobOperatorGetJobInstanceCount(String string) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
return 0;
}

@Override
public int jobOperatorGetJobInstanceCount(String string, String string1) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
return 0;
}

@Override
public Map<Long, String> jobOperatorGetExternalJobInstanceData() {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
return null;
}

@Override
public List<Long> jobOperatorGetJobInstanceIds(String string, int i, int i1) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
return null;
}

@Override
public List<Long> jobOperatorGetJobInstanceIds(String string, String string1, int i, int i1) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
return null;
}

@Override
public Timestamp jobOperatorQueryJobExecutionTimestamp(long l, TimestampType tt) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
return null;
}

@Override
public String jobOperatorQueryJobExecutionBatchStatus(long l) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
return null;
}

@Override
public String jobOperatorQueryJobExecutionExitStatus(long l) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
return null;
}

@Override
public long jobOperatorQueryJobExecutionJobInstanceId(long l) throws NoSuchJobExecutionException {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
return 0;
}

@Override
public List<StepExecution> getStepExecutionsForJobExecution(long l) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
return null;
}

@Override
public Map<String, StepExecution> getMostRecentStepExecutionsForJobInstance(long l) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
return null;
}

@Override
public void updateBatchStatusOnly(long l, BatchStatus bs, Timestamp tmstmp) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
}

@Override
public void markJobStarted(long l, Timestamp tmstmp) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
}

@Override
public void updateWithFinalExecutionStatusesAndTimestamps(long l, BatchStatus bs, String string, Timestamp tmstmp) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
}

@Override
public IJobExecution jobOperatorGetJobExecution(long l) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
return null;
}

@Override
public Properties getParameters(long l) throws NoSuchJobExecutionException {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
return null;
}

@Override
public List<IJobExecution> jobOperatorGetJobExecutions(long l) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
return null;
}

@Override
public Set<Long> jobOperatorGetRunningExecutions(String string) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
return null;
}

@Override
public String getJobCurrentTag(long l) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
return null;
}

@Override
public void purge(String string) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
}

@Override
public JobStatus getJobStatusFromExecution(long l) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
return null;
}

@Override
public long getJobInstanceIdByExecutionId(long l) throws NoSuchJobExecutionException {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
return 0;
}

@Override
public JobInstance createJobInstance(String string, String string1, String string2) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
return null;
}

@Override
public RuntimeJobExecution createJobExecution(JobInstance ji, Properties prprts, BatchStatus bs) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
return null;
}

@Override
public StepExecutionImpl createStepExecution(long l, StepContextImpl sci) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
return null;
}

@Override
public void updateStepExecution(StepContextImpl sci) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
}

@Override
public void updateWithFinalPartitionAggregateStepExecution(long l, StepContextImpl sci) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
}

@Override
public JobStatus createJobStatus(long l) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
return null;
}

@Override
public JobStatus getJobStatus(long l) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource {0}", datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
return null;
}

@Override
public void updateJobStatus(long l, JobStatus js) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
}

@Override
public StepStatus createStepStatus(long l) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
return null;
}

@Override
public StepStatus getStepStatus(long l, String string) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
return null;
}

@Override
public void updateStepStatus(long l, StepStatus ss) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
}

@Override
public String getTagName(long l) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
return null;
}

@Override
public void updateCheckpointData(CheckpointDataKey cdk, CheckpointData cd) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
}

@Override
public CheckpointData getCheckpointData(CheckpointDataKey cdk) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
return null;
}

@Override
public void createCheckpointData(CheckpointDataKey cdk, CheckpointData cd) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
}

@Override
public long getMostRecentExecutionId(long l) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
return 0;
}

@Override
public JobInstance createSubJobInstance(String string, String string1) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
return null;
}

@Override
public RuntimeFlowInSplitExecution createFlowInSplitExecution(JobInstance ji, BatchStatus bs) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
return null;
}

@Override
public StepExecution getStepExecutionByStepExecutionId(long l) {
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, "Unable to find JBatch configured DataSource " + datasourceName);
Logger.getLogger(BatchRuntimeHelper.class.getName()).log(Level.WARNING, message, datasourceName);
return null;
}

Expand Down