Skip to content

#18576 spring cleanup of starter import / reindex error handling#18584

Merged
nollymar merged 26 commits into
masterfrom
issue-18576-starter-xml
Jun 17, 2020
Merged

#18576 spring cleanup of starter import / reindex error handling#18584
nollymar merged 26 commits into
masterfrom
issue-18576-starter-xml

Conversation

@wezell

@wezell wezell commented Jun 3, 2020

Copy link
Copy Markdown
Member

This is a bit of housekeeping (not a rewrite) on how the starter is generated and how it is imported.

removed most of the broken db locking/transaction stuff from the StartupTasksExecutor and importing a starter is now transactional.

moved the Import and Export Utils to their own classes and renamed them ImportStarterUtil and ExportStarterUtil

When serializing and deserializing objects as XML, I am using the BundleUtil which handles writing XML 1.0 correctly.

Heavy cleanup (though not a complete rewrite) on the ImportStarterUtil. It is better but there is risk that I might have been to aggressive and missed something.

I have starters and data sets that cannot be imported and/or reindexed without these changes. Reach out to me if you are looking to test one of them.

db.setSQL("select count(*) as test from inode");
return new DotConnect()
.setSQL("select count(*) as test from inode")
.getInt("test")>0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice I didn't know this one




Try.run(() -> loadStarterSite()).getOrElseThrow(e->new DotRuntimeException(e));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can replace this (e->new DotRuntimeException(e));
by this
(DotRuntimeException::new);

Kinda fancy

httpResponse.setHeader("Content-Disposition", "attachment; filename=" + zipFile.getName());
}

try(final OutputStream outStream = (download)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great

Comment thread dotCMS/src/main/java/com/dotmarketing/db/DotCMSInitDb.java

public void executeStartUpTasks() throws DotDataException {

Logger.debug(this.getClass(), "Running Startup Tasks");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's redundant because there is a Logger.info just below with the same info

boolean identityOn = false;
String cName = _className.substring(_className.lastIndexOf(".") + 1);
String tableName = "";
if (classesWithIdentity.contains(cName) && DbConnectionFactory.isMsSql() && !cName.equalsIgnoreCase("inode")) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* @param out - Printwriter to write responses to Reponse Printwriter so this method can write to
* screen.
*/
private void doXMLFileImport(File f) throws Exception {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public Response indexList(@Context HttpServletRequest httpServletRequest, @Context final HttpServletResponse httpServletResponse, @PathParam("params") String params) {
try {
InitDataObject init = auth(params,httpServletRequest, httpServletResponse);
InitDataObject init = auth(httpServletRequest, httpServletResponse);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
} else if (_importClass.equals(User.class)) {
for (int j = 0; j < l.size(); j++) {
User u = (User) l.get(j);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


if (_className.equals("Counter")) {
counter = true;
} else if (_className.equals("Image")) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

// updating file_type on folder now that structures were added
DotConnect dc = new DotConnect();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private final String oraCreate = "CREATE TABLE \"DB_VERSION\" ( \"DB_VERSION\" INTEGER NOT NULL , \"DATE_UPDATE\" TIMESTAMP NOT NULL, PRIMARY KEY (\"DB_VERSION\") )";
private final String msCreate = "CREATE TABLE db_version ( db_version int NOT NULL , date_update datetime NOT NULL, PRIMARY KEY (db_version) )";

private final String SELECT = "SELECT max(db_version) AS test FROM db_version";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return true;
}
});
} catch (Exception e) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final HashMap<String, String> dcResults = (HashMap<String, String>) l.get(j);

DotConnect dc = new DotConnect();
StringBuffer sb = new StringBuffer("insert into portlet values (?,?,?,?,");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Path("/reindex")
@Produces({MediaType.APPLICATION_JSON})
public Response startReindex(@Context final HttpServletRequest request, @Context final HttpServletResponse response,
@QueryParam("shards") int shards, @DefaultValue(DOTALL) @QueryParam("contentType") String contentType) throws DotDataException, DotSecurityException {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


private final String createTableSQL() {

return (DbConnectionFactory.isPostgres())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy Issue found: Useless parentheses.

indexName = create(indexName, shards, live);
if(indexName == null)
indexName=ContentletIndexAPIImpl.timestampFormatter.format(new Date());
indexName = (live) ? "live_" + indexName : "working_" + indexName;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recordsToIndex = APILocator.getReindexQueueAPI().recordsInQueue();
Logger.info(DotCMSInitDb.class, "Records left to index : " + recordsToIndex);
// ten minutes
if(++counter>30000) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// sorting folder identifiers by parent path in order to pass parent check
Collections.sort(folderIdents, new Comparator<Identifier>() {
public int compare(Identifier o1, Identifier o2) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


DotConnect dc = new DotConnect();
StringBuffer sb = new StringBuffer("insert into portlet values (?,?,?,?,");
if (dcResults.get("narrow").equalsIgnoreCase("f") || dcResults.get("narrow").equalsIgnoreCase("false")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

counter = true;
} else if (_className.equals("Image")) {
image = true;
} else if (_className.equals("Portlet")) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!this.validateZipFile()) {
throw new DotRuntimeException("starter data invalid");
}
final File backTemporalFile = new File(getBackupTempFilePath());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*/
protected boolean hasReindexRecords() throws DotDataException {
DotConnect dc = new DotConnect();
String sql = (DbConnectionFactory.isMsSql())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy Issue found: Useless parentheses.


}
@CloseDBIfOpened
private static void loadStarterSite() throws Exception{

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (filter != null) {
for (Object obj : all)
if (filter.includeIt(obj))
l.add(obj);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


private final String pgCreate = "CREATE TABLE db_version (db_version integer NOT NULL, date_update timestamp with time zone NOT NULL, CONSTRAINT db_version_pkey PRIMARY KEY (db_version));";
private final String myCreate = "CREATE TABLE `db_version` (`db_version` INTEGER UNSIGNED NOT NULL,`date_update` DATETIME NOT NULL, PRIMARY KEY (`db_version`))";
private final String oraCreate = "CREATE TABLE \"DB_VERSION\" ( \"DB_VERSION\" INTEGER NOT NULL , \"DATE_UPDATE\" TIMESTAMP NOT NULL, PRIMARY KEY (\"DB_VERSION\") )";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logger.info(this, "Importing:\t" + _className);


List l = new ArrayList();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* The path where tmp files are stored. This gets wiped alot
*/
private String backupTempFilePath = ConfigUtils.getBackupPath() + File.separator + "temp";
private ArrayList<String> classesWithIdentity = new ArrayList<String>();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

//by an NCLOB field. In the case of dot_containers table, the second field, CODE, is an NCLOB field. Because of this,
//ordering is done only on the first field for the tables, which is INODE
if(com.dotmarketing.beans.Tree.class.equals(clazz)){
_dh.setQuery("from " + clazz.getName() + " order by parent, child, relation_type");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import com.dotcms.content.elasticsearch.business.ContentletIndexAPIImpl;
import com.dotcms.content.elasticsearch.business.IndiciesInfo;
import com.dotmarketing.business.APILocator;
import com.dotmarketing.common.db.DotConnect;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants