All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aoindustries.aoserv.client.web.tomcat.SharedTomcatTable Maven / Gradle / Ivy

There is a newer version: 1.92.0
Show newest version
/*
 * aoserv-client - Java client for the AOServ Platform.
 * Copyright (C) 2001-2012, 2016, 2017, 2018, 2019, 2020  AO Industries, Inc.
 *     [email protected]
 *     7262 Bull Pen Cir
 *     Mobile, AL 36695
 *
 * This file is part of aoserv-client.
 *
 * aoserv-client is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * aoserv-client is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with aoserv-client.  If not, see .
 */
package com.aoindustries.aoserv.client.web.tomcat;

import com.aoindustries.aoserv.client.AOServConnector;
import com.aoindustries.aoserv.client.CachedTableIntegerKey;
import com.aoindustries.aoserv.client.SimpleAOClient;
import com.aoindustries.aoserv.client.account.Account;
import com.aoindustries.aoserv.client.aosh.AOSH;
import com.aoindustries.aoserv.client.aosh.Command;
import com.aoindustries.aoserv.client.billing.Package;
import com.aoindustries.aoserv.client.linux.GroupServer;
import com.aoindustries.aoserv.client.linux.Server;
import com.aoindustries.aoserv.client.linux.UserServer;
import com.aoindustries.aoserv.client.net.Bind;
import com.aoindustries.aoserv.client.schema.AoservProtocol;
import com.aoindustries.aoserv.client.schema.Table;
import com.aoindustries.collections.IntList;
import com.aoindustries.io.TerminalWriter;
import com.aoindustries.io.stream.StreamableInput;
import com.aoindustries.io.stream.StreamableOutput;
import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @see  SharedTomcat
 *
 * @author  AO Industries, Inc.
 */
final public class SharedTomcatTable extends CachedTableIntegerKey {

	SharedTomcatTable(AOServConnector connector) {
		super(connector, SharedTomcat.class);
	}

	private static final OrderBy[] defaultOrderBy = {
		new OrderBy(SharedTomcat.COLUMN_NAME_name, ASCENDING),
		new OrderBy(SharedTomcat.COLUMN_AO_SERVER_name+'.'+Server.COLUMN_HOSTNAME_name, ASCENDING)
	};
	@Override
	protected OrderBy[] getDefaultOrderBy() {
		return defaultOrderBy;
	}

	public int addHttpdSharedTomcat(
		final String name,
		final Server aoServer,
		Version version,
		final UserServer lsa,
		final GroupServer lsg
	) throws IOException, SQLException {
		final int tvPkey = version.getTechnologyVersion(connector).getPkey();
		return connector.requestResult(
			true,
			AoservProtocol.CommandID.ADD,
			new AOServConnector.ResultRequest() {
				int pkey;
				IntList invalidateList;

				@Override
				public void writeRequest(StreamableOutput out) throws IOException {
					out.writeCompressedInt(Table.TableID.HTTPD_SHARED_TOMCATS.ordinal());
					out.writeUTF(name);
					out.writeCompressedInt(aoServer.getPkey());
					out.writeCompressedInt(tvPkey);
					out.writeUTF(lsa.getLinuxAccount_username_id().toString());
					out.writeUTF(lsg.getLinuxGroup_name().toString());
				}

				@Override
				public void readResponse(StreamableInput in) throws IOException, SQLException {
					int code=in.readByte();
					if(code==AoservProtocol.DONE) {
						pkey=in.readCompressedInt();
						invalidateList=AOServConnector.readInvalidateList(in);
					} else {
						AoservProtocol.checkResult(code, in);
						throw new IOException("Unexpected response code: "+code);
					}
				}

				@Override
				public Integer afterRelease() {
					connector.tablesUpdated(invalidateList);
					return pkey;
				}
			}
		);
	}

	public String generateSharedTomcatName(String template) throws IOException, SQLException {
		return connector.requestStringQuery(true, AoservProtocol.CommandID.GENERATE_SHARED_TOMCAT_NAME, template);
	}

	@Override
	public SharedTomcat get(int pkey) throws SQLException, IOException {
		return getUniqueRow(SharedTomcat.COLUMN_PKEY, pkey);
	}

	public SharedTomcat getHttpdSharedTomcat(Worker hw) throws SQLException, IOException {
		return getUniqueRow(SharedTomcat.COLUMN_TOMCAT4_WORKER, hw.getPkey());
	}

	public SharedTomcat getHttpdSharedTomcatByShutdownPort(Bind nb) throws SQLException, IOException {
		return getUniqueRow(SharedTomcat.COLUMN_TOMCAT4_SHUTDOWN_PORT, nb.getId());
	}

	public List getHttpdSharedTomcats(UserServer lsa) throws IOException, SQLException {
		return getIndexedRows(SharedTomcat.COLUMN_LINUX_SERVER_ACCOUNT, lsa.getPkey());
	}

	public List getHttpdSharedTomcats(Package pk) throws IOException, SQLException {
		Account.Name pkname=pk.getName();

		List cached=getRows();
		int size=cached.size();
		List matches=new ArrayList<>(size);
		for(int c=0;c getHttpdSharedTomcats(Server ao) throws IOException, SQLException {
		return getIndexedRows(SharedTomcat.COLUMN_AO_SERVER, ao.getPkey());
	}

	public SharedTomcat getHttpdSharedTomcat(String name, Server ao) throws IOException, SQLException {
		// Use the index first
		List cached=getHttpdSharedTomcats(ao);
		int size=cached.size();
		for(int c=0;c




© 2015 - 2025 Weber Informatics LLC | Privacy Policy